dongni8969 2015-09-19 06:34
浏览 10
已采纳

如何以这种方式打印多个服务

I want to print both result in php

In file A

$_SESSION['cart']['prices'][] = array('1000');

$_SESSION['cart']['services'][] = array('game');

In File B

$_SESSION['cart']['prices'][] = array('2000');

$_SESSION['cart']['services'][] = array('game2');

In file C

foreach ($_SESSION['cart']['services'] as $key => $service) {
  echo $service . ' = ' . $_SESSION['cart']['prices'][$key] . '<br />';
}

ERROR E_NOTICE : type 8 -- Array to string conversion -- at echo line

  • 写回答

1条回答 默认 最新

  • dongqiuge5435 2015-09-19 06:57
    关注

    You insert services/prices as another array. So use this and it will be ok:

    I want to print both result in php

    In file A

    $_SESSION['cart']['prices'][] = '1000';
    
    $_SESSION['cart']['services'][] = 'game';
    

    In File B

    $_SESSION['cart']['prices'][] = '2000';
    
    $_SESSION['cart']['services'][] = 'game2';
    

    In file C

    foreach ($_SESSION['cart']['services'] as $key => $service) {
      echo $service . ' = ' . $_SESSION['cart']['prices'][$key] . '<br />';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?