Posts

Showing posts with the label php array

php multidimensional array to single dimension array

<?php  php convert multidimensional array to single dimension array convert multidimensional array to single array php function  multidimensional_array_to_single_dimension_array ( $array ) {     if (! $array ) return  false ;     $flat  = array();     $iterator   = new  RecursiveIteratorIterator (new  RecursiveArrayIterator ( $array ));       foreach ( $iterator  as  $value )  $singhal [] =  $value ;    return  $singhal ; } $arr =array( 1 , 2 ,array( 4 , 5 ), 6 ,array( 7 , 8 ,array( 9 , 10 , 11 ,array( 12 , 13 , 14 ))));     print_r ( multidimensional_array_to_single_dimension_array ( $arr )); ?> OUTPUT: Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 [4] => 6 [5] => 7 [6] => 8 [7] => 9 [8] => 10 [9] => 11 [10] => 12 [11] => 13 [12] =...

How to php convert associative array to indexed array in PHP

get index  of array in php <?php $arr =array( 'index1'  => 'value1'  ,  "index2"  => 'value2'  ,  "index3" => 'value3' );  $ar = array_values ( $arr );  // convert to indexing  array  $key = array_keys ( $arr );  // get index name  for( $i = 0 ;  $i <  count ( $ar ) ;  $i ++){ echo  $key [ $i ]. "=" . $ar [ $i ]. "<br> " ; }   ?> output index1=value1 index2=value2 index3=value3