How to I return the key number I just added to an array in PHP by using [ ]? -
i have while loop, , in loop appending keys array using
$my_array[] = $array_element;
code snippet:
<?php $raw_string = 'david,frank,hal9000,victor,jack,charles' $put_into_array = explode(',', $raw_string); $my_array = array(); foreach($put_into_array $array_element){ if($array_element != 'hal9000'){ $living_crew[] = $array_element; if( //the array key 2nd key// ){ $lost_in_space_by = $tried_to_retrieve; ////do here//// } if( //the array key 1st key// ){ $tried_to_retrieve = //this key//; } } } ?>
i looking way value added [] infront of $my_array. know particular example can solved in other ways, point learn function, not solve 1 example in other ways. expected behave similar now-depricated mysql_insert_id() function.
thanks!
use
$idx = array_push($living_crew, $xxx) - 1
instead of
$living_crew[] = $xxx;
it returns length of array. see http://php.net/manual/en/function.array-push.php
Comments
Post a Comment