2016-03-17 15:48
浏览 99


I'm trying to call this array but I'm getting an Array to string conversion Error. I'm not sure what I'm doing wrong, I'm just learning. If anyone could help me get this set up correctly I would greatly appreciate it!


public function getPricing()
    $windows = array("Storm Windows" => array("(includes removal, cleaning, 
                                            and replacement)", " - $12.00")
                    , "Double Hung" => array("(opens up and down)" ,
                                             " - $9.00")
                    , "Casement" => array("(crank out or stationary
                                             window)" ," - $8.00")
                    , "Transom" => array("(rectangle window over top of a   
                                             window)" ," - $3.00")

  return view('pages.pricing')
      ->with("windows", $windows);


Calling it in the view:

   @foreach ($windows as $window => $DescriptionPrice)
        <h2>{{$window . $DescriptionPrice}}</h2>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douyun6781 2016-03-17 15:57

    Try this code: You were tying to output an array which is not a string. So, you need to select the array item you need to print out as shown below.

    @foreach ($windows as $window => $DescriptionPrice)
       <h2>For {{ $window }} - {{$DescriptionPrice[0]}} - {{$DescriptionPrice[1]}}</h2>
    解决 无用
    打赏 举报
  • drnbotxo449747 2016-03-17 15:57

    $DescriptionPrice is an array so can't be output as a string. You will need to do something like this instead:-

    @foreach ($windows as $window => $DescriptionPrice)
        <h2>{{$window}} {{$DescriptionPrice[0]}} {{$DescriptionPrice[1]}}</h2>
    解决 无用
    打赏 举报

相关推荐 更多相似问题