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!
Array:
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>
@endforeach
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>
@endforeach
$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>
@endforeach