我具有一個陣列,它是這樣如何從兩個或更多陣列
Array
(
[sch_name] => example
[sch_degree] => example
[sch_field] => example
[sch_grade] => example
[sch_from_year] => 2008
[sch_to_year] => 2008
[sch_desc] => example
)
&更同一陣列像上面,現在,當我另一個陣列添加到它,它看起來像示出創建多維數組下面
Array
(
[0] => Array
(
[sch_name] => example
[sch_degree] => example
[sch_field] => example
[sch_grade] => example
[sch_from_year] => 2008
[sch_to_year] => 2008
[sch_desc] => example
)
[1] => Array
(
[sch_name] => example
[sch_degree] => example
[sch_field] => example
[sch_grade] => example
[sch_from_year] => 2008
[sch_to_year] => 2008
[sch_desc] => example
)
)
現在的問題是在第三陣列被附加到[1]數組像下面所示
Array
(
[0] => Array
(
[sch_name] => example
[sch_degree] => example
[sch_field] => example
[sch_grade] => example
[sch_from_year] => 2008
[sch_to_year] => 2008
[sch_desc] => example
)
[1] => Array
(
[0] => Array
(
[sch_name] => example
[sch_degree] => example
[sch_field] => example
[sch_grade] => example
[sch_from_year] => 2008
[sch_to_year] => 2008
[sch_desc] => example
)
[1] => Array
(
[sch_name] => example
[sch_degree] => example
[sch_field] => example
[sch_grade] => example
[sch_from_year] => 2008
[sch_to_year] => 2008
[sch_desc] => example
)
)
)
我想新的陣列將被追加爲[2] &如果增加更多的數組,那麼它應該是這樣的[3]
這是我如何做到這一點
$post = array();
$post['sch_name'] = test_input($sch_name);
$post['sch_degree'] = test_input($sch_degree);
$post['sch_field'] = test_input($sch_field);
$post['sch_grade'] = test_input($sch_grade);
$post['sch_from_year'] = test_input($sch_from_year);
$post['sch_to_year'] = test_input($sch_to_year);
$post['sch_desc'] = test_input($sch_desc);
$newArray = array($post, $array_from_db);
$ array_from_db是從數據庫中提取正如我在問題開始部分所示
你爲什麼不使用'array_push'? –
如果'$ array_from_db'包含兩個子數組,並且新數組是'$ post',那麼只需試試'array_push($ array_from_db,$ post);'$ array_from_db'將被更新。 –
當我嘗試$ newArray = array_push($ in,$ post); print_r($ newArray);出口;它打印8 –