I have this stdclass object in array
Array ( [0] => stdClass Object ( [file_id] => 6 [file_name] => 1ofdays.wav ) [1] => stdClass Object ( [file_id] => 7 [file_name] => abcd.mp3 ) )
I want to convert this stdclass
object array into associative arrays such as
$name_array=([text]=>1ofdays.wav,[text]=>abcd.mp3);
$id_array=([value]=>6,[value]=>7);
I tried achieving it by first flattening the array using this function
public function array_flatten($mArray) {
$sArray = array();
foreach ($mArray as $row) {
if ( !(is_array($row)) ) {
if($sArray[] = $row){
}
} else {
$sArray = array_merge($sArray,$this->array_flatten($row));
}
}
return $sArray;
}
This function gave me result
Array ( [0] => 6 [1] => 1ofdays.wav [2] => 7 [3] => abcd.mp3 )
then I created two arrays even()
and odd()
and took elements from odd and even indexes of the and pushed them in their respected arrays
which resulted in
even( [0] => 6 [1] => 7 )
odd( [0] => 1ofdays.wav [1] => abcd.mp3 )
now i want to put elements of even array into
Id_array =('value'=>6,'value'=>7)
and
name_array=('text'=>1ofdays.wav,'text'=>'abcd.mp3')