0

Good day

below is my ARRAY output

how do i load the price of a SKU by name?

i need the price of SKU PRODUCT1 for example which is 39.99 the array comes from a CSV which is converted to ARRAY

rough example

$SKU = "Product1";
$price = ['SKU']array; #somehow
echo $price;

Array output:


 array(5) {
  [0]=>
  array(5) {
    [0]=>
    string(3) "SKU"
    [1]=>
    string(7) "Product"
    [2]=>
    string(5) "Price"
    [3]=>
    string(11) "Description"
    [4]=>
    string(5) "Image"
  }
  [1]=>
  array(5) {
    [0]=>
    string(4) "PRODUCT1"
    [1]=>
    string(23) "Product Name stuff 1"
    [2]=>
    string(7) "$39.99 "
    [3]=>
    string(47) "desrption"
    [4]=>
    string(12) "product1.png"
  }
  [2]=>
  array(5) {
    [0]=>
    string(4) "PRODUCT2"
    [1]=>
    string(13) "Product Name 2 stuff "
    [2]=>
    string(7) "$49.99 "
    [3]=>
    string(47) "product2descr"
    [4]=>
    string(11) "product2.png"
  }

}

Good day

below is my ARRAY output

how do i load the price of a SKU by name?

i need the price of SKU PRODUCT1 for example which is 39.99 the array comes from a CSV which is converted to ARRAY

rough example

0

1 Answer 1

0

Assuming the array is named $a, loop through each row and look for the SKU in the first column:

foreach ( $a as $row ) {
  if ( $row[0] == 'PRODUCT1' ) {
    echo $row[2]; // Price
    break;
  }
}
Sign up to request clarification or add additional context in comments.

6 Comments

thank you what if more Rows are added?
returned null foreach ( $a as $row ) { if ( $row[0] == 'PRODUCT1' ) { echo $row[2]; // Price break; } }
@kmoser Please close questions which have been asked and answered before.
really wheres the answer that has these elements layout?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.