【问题标题】:Array in loop PHP Looping through arrays with for loop循环中的数组 PHP 使用 for 循环遍历数组
【发布时间】:2018-11-28 08:56:12
【问题描述】:

嗨,我可以在数组中使用循环吗?能帮我看看怎么用吗?

    if($oran->typeid =="235")
        {
            foreach($oran->fields as $yoran)  
                {
        $tip = "Name";
        $say = count($yoran);       
            for($i=0; $i<$say; $i++) {
        $array73 = array(
            "tip" => $tip,
            "id" => 42,
            "values" => array(
                              "1"=>array("tur"=>"$yoran->desc","tid"=>"233","val"=>$yoran->value,
                              )));  
            }
        array_push($kod,$array73);
        }}

我想要什么...

>  for($i=0; $i<$say; $i++) {
>                                    
>      "1"=>array("tur"=>"$yoran->desc","tid"=>"233","val"=>$yoran->value,
>     )
>     
>       }

我正在动态尝试填充多维数组并遇到了一些麻烦。

https://i.ibb.co/CKCrF3X/asd.jpg

【问题讨论】:

  • 正确的缩进有助于代码可视化
  • 您需要对数组进行索引,如下所示:$yoran[$i]-&gt;value。这是假设它是一个带有数字键的数组。
  • 如何在数组中使用循环
  • 这就是你想要做的吗? sandbox.onlinephpfunctions.com/code/…
  • @Jules R 非常感谢您的帮助。对不起,我的英语不是很好。我已经添加了照片,请您查看一下吗? i.ibb.co/CKCrF3X/asd.jpg

标签: php arrays loops foreach


【解决方案1】:

我没有完全理解你想做什么, 但我相信array_map 会帮助你

【讨论】:

  • 我想要什么。 --> "1"=>​​array("tur"=>"$yoran->desc","tid"=>"233","val"=>$yoran->value," 2 3 4 5 (数组在数组循环中)
  • PHP 解析错误:语法错误,意外 'for' (T_FOR),期待 ')'
猜你喜欢
  • 2015-07-09
  • 1970-01-01
  • 1970-01-01
  • 2019-07-10
  • 2013-11-23
  • 2011-05-23
  • 2012-11-14
  • 2011-04-25
  • 1970-01-01
相关资源
最近更新 更多