傢伙,我有多維數組我與這個以下數組得到它從$menu_order
var_dump
:如何在笨返回多維數組
array(5) {
[0]=>
array(1) {
[0]=>
array(1) {
["variant_name"]=>
string(5) "Spicy"
}
}
[1]=>
array(2) {
[0]=>
array(1) {
["variant_name"]=>
string(5) "Spicy"
}
[1]=>
array(1) {
["variant_name"]=>
string(5) "small"
}
}
[2]=>
array(2) {
[0]=>
array(1) {
["variant_name"]=>
string(5) "Salty"
}
[1]=>
array(1) {
["variant_name"]=>
string(6) "medium"
}
}
[3]=>
array(2) {
[0]=>
array(1) {
["variant_name"]=>
string(12) "Mix of Herbs"
}
[1]=>
array(1) {
["variant_name"]=>
string(5) "large"
}
}
[4]=>
array(0) {
}
}
這個數組,我需要得到variant_name
成爲variant_menu_id
本以下代碼:
foreach ($menu_order as $item) {
if (isset($item[0]["variant_name"])) {
foreach($item as $value) {
$variant_id[] = $this->Main_home_m->m_get_choice_id($value["variant_name"]);
}
} else {
$variant_id[] = array();
}
}
的m_get_choice_id
模型有這樣下面的代碼:
Function m_get_choice_id($variant_name){
$this->db->select("variant_menu_id");
$this->db->from("uhd_variant_menu");
$this->db->where("variant_name",$variant_name);
$query = $this->db->get();
return $query->row_array();
}
的variant_id
會回到這個多維數組:
array(8) {
[0]=>
array(1) {
["variant_menu_id"]=>
string(1) "3"
}
[1]=>
array(1) {
["variant_menu_id"]=>
string(1) "3"
}
[2]=>
array(1) {
["variant_menu_id"]=>
string(1) "6"
}
[3]=>
array(1) {
["variant_menu_id"]=>
string(1) "4"
}
[4]=>
array(1) {
["variant_menu_id"]=>
string(1) "7"
}
[5]=>
array(1) {
["variant_menu_id"]=>
string(1) "5"
}
[6]=>
array(1) {
["variant_menu_id"]=>
string(1) "8"
}
[7]=>
array(0) {
}
}
,但我想要的結果variant_id
成爲這個多維數組:
array(5) {
[0]=>
array(1) {
[0]=>
string(1) "3"
}
[1]=>
array(2) {
[0]=>
string(1) "3"
[1]=>
string(1) "6"
}
[2]=>
array(2) {
[0]=>
string(1) "4"
[1]=>
string(1) "7"
}
[3]=>
array(2) {
[0]=>
string(1) "5"
[1]=>
string(1) "8"
}
[4]=>
array(0) {
}
}
傢伙你能幫助我如何獲得多維陣列?
謝謝(:
只需先訪問變體ID,然後按下它即可 – Ghost
你能告訴我怎麼做嗎?@Ghost – Kelvin