我并试图让 if else() 语句在执行之前查找 2 个或更多条件,但它对我不起作用.. 例如,我的最终目标是搜索 array[Pack] 和 if [Type] == s45 && [ packageA1] 存在然后使用 array_slice 将附加信息添加到 [Type array]
if() 条件可以正常工作,但 else if() 则不行......
$节点:
Array
(
[Pack] => Array
(
[Type] => s45
[packageA1] => Array
(
[level] => REMOVE FROM DB
[stage] => REMOVE FROM DB
[description] => s45 info here
[image] =>
)
)
[Pack2] => Array
(
[Type] => s99
[packageA1] => Array
(
[level] => REMOVE FROM DB
[stage] => REMOVE FROM DB
[description] => s99 info goes here
[image] =>
)
)
)
//more code...
$i = 1;
if(!array_key_exists($item[0], $node)){
$node[$row[0]] = array("Type" => $item[0], "package".$item[1] => array("level" => "REMOVE FROM DB", "stage" => "REMOVE FROM DB", "description" => $item[3], "image" => $item[4]));
}else if(array_key_exists($item[0], $node) && array_key_exists("package".$item[1], $node)){
$i++;
$res = array_slice($node[$rowKey], 0, $i, true) + array("my_key" => "my_value") + array_slice($node[$rowKey], $i, count($node[$rowKey]) - 1, true);
}
预期输出:
Array
(
[Pack] => Array
(
[Type] => s45
[packageA1] => Array
(
[level] => REMOVE FROM DB
[stage] => REMOVE FROM DB
[description] => s45 info here
[image] =>
)
[packageA2] => Array
(
[level] => REMOVE FROM DB
[stage] => REMOVE FROM DB
[description] => blahhhhhh blah blahh
[image] =>
)
[packageE1] => Array
(
[level] => REMOVE FROM DB
[stage] => REMOVE FROM DB
[description] => moar random stuff inserted
[image] =>
)
)
[Pack2] => Array
(
[Type] => s99
[packageA1] => Array
(
[level] => REMOVE FROM DB
[stage] => REMOVE FROM DB
[description] => s99 info goes here
[image] =>
)
)
)