doujianguang5506 2014-07-28 20:26
浏览 58
已采纳

匹配2个数组之间的字符串

In my PHP example below I have Item data and Amount data - How could I get it to output

Item 1 23 etc

PHP:

array(3) {
  [0]=>
  string(6) "Item 1"
  [1]=>
  string(6) "item 2"
  [2]=>
  string(6) "item 3"
}
array(3) {
  [0]=>
  string(2) "23"
  [1]=>
  string(2) "90"
  [2]=>
  string(2) "23"
}
  • 写回答

2条回答 默认 最新

  • dream1849 2014-07-28 20:33
    关注

    Try something like this:

    $item = array("Item 1","item 2","item 3") ;
    $amount = array("23","90","23") ;
    
    foreach ($item as $key => $value) {
        $result_array[] = $value." ".$amount[$key];
    }
    print_r($result_array);
    

    OUTPUT

    Array
    (
        [0] => Item 1 23
        [1] => item 2 90
        [2] => item 3 23
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?