我有一个while循环,在循环中,我使用以下命令将键附加到数组中
$my_array[] = $array_element;
程式码片段:
<?php
$raw_string = 'David,Frank,Hal9000,Victor,Jack,Charles'
$put_into_array = explode(',', $raw_string);
$my_array = array();
foreach($put_into_array AS $array_element){
if($array_element != 'Hal9000'){
$living_crew[] = $array_element;
if( //The array key is the 2nd key// ){
$lost_in_space_by = $tried_to_retrieve;
////DO SOMETHING HERE////
}
if( //The array key is the 1st key// ){
$tried_to_retrieve = //this key//;
}
}
}
?>
我正在寻找一种方法,以获取刚刚在$ my_array的[]前面添加的值。我知道这个特定示例可以通过其他方式解决,但是重点是学习功能,而不是以其他方式解决这个示例。预期它的行为类似于现在描述的mysql_insert_id()函数。
谢谢!
采用
$idx = array_push($living_crew, $xxx) - 1
代替
$living_crew[] = $xxx;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句