Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Array values - I need to know if they are definitely empty
    primarykey
    data
    text
    <p>Here is my example array $postcodeSuppliers:</p> <pre><code>Array ( [0] =&gt; AB123 [postcode] =&gt; AB123 [1] =&gt; TEST [supplier_1] =&gt; TEST [2] =&gt; [supplier_2] =&gt; [3] =&gt; [supplier_3] =&gt; ) </code></pre> <p>I have been trying to confirm whether a supplier is empty. Here is the code I have been using for this:</p> <pre><code>function generateQuoteSuppliers($postcodeSuppliers) { $quoteSupplier = array("supplier_1", "supplier_2", "supplier_3"); //print("&lt;pre&gt;"); //print_r($postcodeSuppliers); //print("&lt;/pre&gt;"); for ($i = 1; $i &lt; 4; $i++) { $supplier = $postcodeSuppliers['supplier_' . $i . '']; //if ($supplier == '') //if (!isset($supplier)) if (empty($supplier)) { //A fake supplier is added here 'FAKE' if any of the 3 suppliers contain no date echo "NO SUPPLIER"; $quoteSupplier['supplier_' . $i . ''] = array ( 'supplier' =&gt; 'FAKE', 'price' =&gt; 0 ); } else { $quoteSupplier['supplier_' . $i . ''] = array ( 'supplier' =&gt; $postcodeSuppliers['supplier_' . $i . ''], 'price' =&gt; 0 ); } } return $quoteSupplier; } </code></pre> <p>None of the methods I have been using to check if the value is empty are working. I get this:</p> <pre><code>Array ( [0] =&gt; supplier_1 [1] =&gt; supplier_2 [2] =&gt; supplier_3 [supplier_1] =&gt; Array ( [supplier] =&gt; TEST [price] =&gt; 0 ) [supplier_2] =&gt; Array ( [supplier] =&gt; [price] =&gt; 0 ) [supplier_3] =&gt; Array ( [supplier] =&gt; [price] =&gt; 0 ) ) </code></pre> <p>When I am expecting this:</p> <pre><code>Array ( [0] =&gt; supplier_1 [1] =&gt; supplier_2 [2] =&gt; supplier_3 [supplier_1] =&gt; Array ( [supplier] =&gt; TEST [price] =&gt; 0 ) [supplier_2] =&gt; Array ( [supplier] =&gt; FAKE [price] =&gt; 0 ) [supplier_3] =&gt; Array ( [supplier] =&gt; FAKE [price] =&gt; 0 ) ) </code></pre> <p>Can someone show me where I am going wrong please? I am completely open to the fact I am wrong! or using my array incorrectly.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload