php如果不在数组中,PHP如果在数组中找不到,则取消设置父级

如果我没有在我的子元素身上找到我的针,我有一个问题会导致我的父级不能正常工作,出于某种原因,无论我尝试多少种不同的方式,我都无法使其工作,有人可能会将我指向正确的方向吗?这是在一个底层深度约为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 '
';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值