Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从多维数组取消设置数组_Php_Arrays_For Loop_Multidimensional Array_Key - Fatal编程技术网

Php 从多维数组取消设置数组

Php 从多维数组取消设置数组,php,arrays,for-loop,multidimensional-array,key,Php,Arrays,For Loop,Multidimensional Array,Key,我希望迭代一个多维数组,并删除“approved”设置为零的数组。我曾尝试使用其他stackoverflow线程中建议的unset方法,但没有效果。我还尝试按照重新索引数组 任何帮助都将不胜感激 实际上,您的代码看起来是正确的!检查这个快速测试,它运行良好,并输出一行代码来调试每个牙医: <? $dentists = array( array( 'name' => 'kevin', 'approved' => 0, ),

我希望迭代一个多维数组,并删除“approved”设置为零的数组。我曾尝试使用其他stackoverflow线程中建议的
unset
方法,但没有效果。我还尝试按照重新索引数组


任何帮助都将不胜感激

实际上,您的代码看起来是正确的!检查这个快速测试,它运行良好,并输出一行代码来调试每个牙医:

<?
$dentists = array(
    array(
        'name' => 'kevin',
        'approved' => 0,
    ),
    array(
        'name' => 'cathy',
        'approved' => 0,
    ),
    array(
        'name' => 'steven',
        'approved' => 1,
    ),
);

foreach ($dentists as $key => $dentists_index) {
    print "Dentist #$key - Approved: " . $dentists_index['approved'] . "<br />\n";

  if($dentists_index['approved'] == 0) {
    unset($dentists[$key]);
  }
}

var_dump($dentists);
?>


调整您的账户费率:这应该很好。如果没有,那么要么你在某个地方输入了一个错误,不管什么原因,这个条件都不是真的。粘贴你的数组样本,意味着它看起来如何。我们会更容易work@WebnetMobile.com我没有接受的问题还没有得到回答。谢谢@Jon,我需要重新编制索引吗?
<?
$dentists = array(
    array(
        'name' => 'kevin',
        'approved' => 0,
    ),
    array(
        'name' => 'cathy',
        'approved' => 0,
    ),
    array(
        'name' => 'steven',
        'approved' => 1,
    ),
);

foreach ($dentists as $key => $dentists_index) {
    print "Dentist #$key - Approved: " . $dentists_index['approved'] . "<br />\n";

  if($dentists_index['approved'] == 0) {
    unset($dentists[$key]);
  }
}

var_dump($dentists);
?>