如果我没有在我的子元素身上找到我的针,我有一个问题会导致我的父级不能正常工作,出于某种原因,无论我尝试多少种不同的方式,我都无法使其工作,有人可能会将我指向正确的方向吗?这是在一个底层深度约为4的多维数组中抛出的。下面是代码和数组的一部分可能的样子。在这种情况下,只有Array [3]应该保留,Array的[1-2]应该被删除。
array (
1 =>
array (
197015 =>
array (
345415 =>
array (
'options' =>
array (
'Name on Credential' => '',
'Ordination Month' => '',
'Ordination Day' => '',
'Ordination Year' => '',
'Badge Choice?' => '',
),
'comments' =>
array (
213354 => '',
),
'products_name' => '',
'products_quantity' => '',
'delivery_country' => '',
'customers_name' => '',
'delivery_name' => '',
'delivery_street_address' => '',
'delivery_city' => '',
'delivery_postcode' => '',
'delivery_state' => '',
'customers_telephone' => '',
),
),
),
2 =>
array (
197014 =>
array (
345414 =>
array (
'options' =>
array (
'Name on Credential' => '',
'Ordination Month' => '',
'Ordination Day' => '',
'Ordination Year' => '',
'Badge Choice?' => '',
),
'comments' =>
array (
213353 => '',
),
'products_name' => '',
'products_quantity' => '',
'delivery_country' => '',
'customers_name' => '',
'delivery_name' => '',
'delivery_street_address' => '',
'delivery_city' => '',
'delivery_postcode' => '',
'delivery_state' => '',
'customers_telephone' => '',
),
),
),
3 =>
array (
197013 =>
array (
345412 =>
array (
'options' =>
array (
'Name on Credential' => '',
'Ordination Month' => '',
'Ordination Day' => '',
'Ordination Year' => '',
),
'comments' =>
array (
213352 => '',
),
'products_name' => 'Jedi',
'products_quantity' => '1',
'delivery_country' => '',
'customers_name' => '',
'delivery_name' => '',
'delivery_street_address' => '',
'delivery_city' => '',
'delivery_postcode' => '',
'delivery_state' => '',
'customers_telephone' => '',
),
345413 =>
array (
'options' =>
array (
'' => '',
),
'comments' =>
array (
213352 => '',
),
'products_name' => '',
'products_quantity' => '',
'delivery_country' => '',
'customers_name' => '',
'delivery_name' => '',
'delivery_street_address' => '',
'delivery_city' => '',
'delivery_postcode' => '',
'delivery_state' => '',
'customers_telephone' => '',
),
),
),下面是我尝试使用的最后一个代码示例,但没有成功,如果您替换unset($ k);返回错误;它将返回针出现在哪个辅助阵列。
// array_search with recursive searching, optional partial matches and optional search by key
function array_find_r($needle, &$haystack, $partial_matches = false, $search_keys = false) {
if(!is_array($haystack)) return false;
foreach($haystack as $key=>&$value) {
$what = ($search_keys) ? $key : $value;
if($needle===$what) return $key;
else if($partial_matches && @strpos($what, $needle)!==false) return $key;
else if(is_array($value) && array_find_r($needle, $value, $partial_matches, $search_keys)!==false) return $key;
}
unset($k);
}
$tty = array();
foreach($datas as &$k) {
$tty[] = array_find_r('Jedi', &$k, true, false);
}
$tty=array_filter($tty); rsort($tty);
echo '
'; var_export($datas); echo '';