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

1 Answers1

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;
  }
}
kmoser
  • 8,780
  • 3
  • 24
  • 40