Hello, I’ve fixed the problem of getting the ajax data and sorting it by key, but now another problem has arisen.
When my array is declared outside if (isset ($ _ POST [’’ pColors]), it remains empty.
if aray is outside if output:
Array()
if aray is inside if output:
Array
(
[5] => Array
(
[pColors] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
)
)
This is the code I use:
$x = $getProductID;
$_SESSION['pColors'] = array(); // outside
if(isset($_POST['pColors'])) {
$_SESSION['pColors'] = array(); // inside
foreach($_POST as $colorKey => $value) {
if ($colorKey == 'pColors') {
$_SESSION['pColors'][$x][$colorKey] = $value;
}
}
}
if (!empty($_SESSION['pColors'])) {
echo 'empty ! ';
} else { echo 'none empty ! '; }
print_r($x);
echo '<pre>';
print_r($_SESSION['pColors']);
echo '</pre>';