3points Save QUESTION 2 You are trying to use two-dimensional array (shown below
ID: 3881659 • Letter: 3
Question
3points Save QUESTION 2 You are trying to use two-dimensional array (shown below) for handling data. W line of code to access the price for 'Spark Plugs'? $products= array array 'Code' TIR', Description=> Tires', 'Price'-> 100), -4): array('Code' => 'PK', 'Description'-> 'Spark Plugs', 'Price' Sproducts " array( array CodeTIR Tires Description Price/W 100 Code Description Price 100 array( "Code"#> OIL TIR Tires 10 Price10 OIL sPK Spak Plugs rrayt Code SPK product attribute Description' Spark Plugs.Explanation / Answer
$product = array(
array(
"Code"=>"TIR",
"Description"=>"Tires",
"Price"=>100
),
array(
"Code"=>"OIL",
"Description"=>"Oil",
"Price"=>10
),
array(
"Code"=>"SPK",
"Description"=>"Spark",
"Price"=>4
),
);
If you notice carefully, "Spark Plugs" represents the third column in the products array (i.e., row index = 2 since index always starts from 0).
Therefore to access "Spark Plugs" row, we can do $product[2].
Now, to get the the price we can do the following:
echo "Price of Spark Plugs is : ".$product[2]["Price"];
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.