PHP循环遍历多维数组并更改值

前端之家收集整理的这篇文章主要介绍了PHP循环遍历多维数组并更改值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在下面有一个多维数组,我想循环遍历它并将[menu_cats]的值从一个数字更改为一个字符串,该字符串是从数据库选择中提取的.这可能吗?数组的名称是’result’.
Array
(
[0] => Array
    (
        [0] => Array
            (
                [menu_cats] => 1                    
                [item] => Introduction
                [link] => needs
            )

        [1] => Array
            (
                [menu_cats] => 1
                [item] => Needs Assessment
                [link] => needs/needs.PHP
            )

    )

[1] => Array
    (
        [0] => Array
            (
                [menu_cats] => 2                    
                [item] => Introduction
                [link] => knowledge
            )

        [1] => Array
            (
                [menu_cats] => 2
                [item] => Administer Knowledge Pre-Test
                [link] => knowledge/pre_test.PHP
            )
    )

)
foreach($result as $key => $subarray) {
   foreach($subarray as $subkey => $subsubarray) {
      $result[$key][$subkey]['menu_cats'] = 'your string here';
   }
}
原文链接:https://www.f2er.com/php/134232.html

猜你在找的PHP相关文章