I can't seem to get any results from the following foreach code. I can't seem to recursively run through the array and i can't make a smaller array of this array. I just want to cherry pick data from the array and place the data in much smaller arrays.
PHP CODE
$ii = 0;
foreach ($array as $key => $value)
{
$vv = $value;
if($vv== 'Alpha')
{
$ii++;
$list[$ii]['info'] = $vv; // my new array
}
}
PHP print_r($array)
Array
(
[0] => Array
(
[moredetails] => Array
(
[moredetails] => Array
(
[0] => Array
(
[productId] => 9999
[productName] => Name
[productType] => Alpha
[serialNumber] =>
[serviceItemId] => 123456
)
[1] => Array
(
[productId] => 8888
[productName] => Name
[productType] => Beta
[serialNumber] =>
[serviceItemId] => 123456
)
)
)
)
)
Ideal Result
Array
(
[0]
(
[productID] => 9999
[productName] => Name
{productType] => Alpha
)
)
Solution Found!
function miniArray($array, &$simple, $ii)
{
foreach($array as $key => $value)
{
if(is_array($value)){
$ii++;
miniArray($value, $simple, $ii);
}
else
{
$simple[$ii][$key] = $value;
}
}
}
miniArray($service, $simple_array, 0);
foreachdoesn't loop recursively through an array. you'll have to write a custom function for that.array_walk_recursive. I suggest you look around in the PHP manual a little to find even more options: php.net/arrays and for the basics of the array itself: php.net/array