多维数组以在 php 中转换为字符串

Array ( [11] => Array ( [0] => A [1] => Attempt ) [ 12] => Array ( [0] => 0 [1] => None ) [ 13] => Array ( [0] => 0 [1] => None ) [ 14] => Array ( [0] => 0 [1] => None ) [ 15] => Array ( [0] => 0 [1] => None ) [ 16] => Array ( [0] => 0 [1] => None ) )

这是我的数组,但我想要以下 STRING 格式:


11=>A=>Attempt,12=>0=>None,13=>0=>None,14=>0=>None,15=>0=>None,16=>0=>None


  1. $keys=array_keys($total_answer)

   2.     for($i=0;$i<count($keys);$i++)

    3.   {

      4.      for($j=0;$j<count($total_answer[$keys[$i]]);$j++)

        5.    {

          6.     echo $total_answer[$keys[$i]][$j]

           7. //Here I am getting confuse to make string 


Thank You In Advance:)


智慧大石
浏览 142回答 2
2回答

jeck猫

一种方法,<?php$array = array ( "11" => array ( "0" => "A" ,"1" => "Attempt" ) ,"12" => array ( "0" => 0, "1" => "None" ) ,"13" => array ( "0" => 0, "1" => "None" ) ,"14" => array ( "0" => 0 ,"1" => "None" ), "15" => array ( "0" => 0, "1" => "None" ), "16" => array ( "0" => 0, "1" => "None" ) );foreach($array as $key=>$value){&nbsp; &nbsp; $expected[] = $key.'=>'.$value[0].'=>'.$value[1];}echo implode(',',$expected);?>工作演示:https ://3v4l.org/TDb0A

慕少森

一个foreach就够了&nbsp; &nbsp; $out = [];&nbsp; &nbsp; foreach ($total_answer as $k=>$v)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; array_unshift($v, $k);&nbsp; &nbsp; &nbsp; &nbsp; $out[] = implode('=>', $v);&nbsp; &nbsp; }&nbsp; &nbsp; echo implode(',', $out);
打开App,查看更多内容
随时随地看视频慕课网APP