Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Array Setup from Variable
    primarykey
    data
    text
    <p>I have a list of items I want to feed to an API via an array but it is built from a separate object. I was thinking I could loop through the items in the object to construct a variable I could then feed to the array but something is disconnected. This is probably easier to see than it is to explain.</p> <p>The code I am using is this:</p> <pre><code>//Set up the parser object $parser = new XMLParser($xml); $parser-&gt;Parse(); $skuList = ''; // Pull the inventory of the requested SKUs from Magento for comparison later foreach($parser-&gt;document-&gt;product as $product) { $skuList .= "'" . $product-&gt;sku[0]-&gt;tagData . "',"; } echo $skuList; print_r( $proxy-&gt;call($sessionId, 'product_stock.list', array(array($skuList)))); </code></pre> <p>If I run this at the command line I get </p> <pre><code>'1DAFPOT5','8GAIL','26BULK30',Array ( ) </code></pre> <p>Now if I change the print_r line by putting the contents of the variable directly in the call like this </p> <pre><code>print_r( $proxy-&gt;call($sessionId, 'product_stock.list', array(array('1DAFPOT5','8GAIL','26BULK30', )))); </code></pre> <p>I get this output which is what I am looking for</p> <pre><code>'1DAFPOT5','8GAIL','26BULK30',Array ( [0] =&gt; Array ( [product_id] =&gt; 2154 [sku] =&gt; 26BULK30 [qty] =&gt; 19.0000 [is_in_stock] =&gt; 1 ) [1] =&gt; Array ( [product_id] =&gt; 2255 [sku] =&gt; 8GAIL [qty] =&gt; 16.0000 [is_in_stock] =&gt; 1 ) [2] =&gt; Array ( [product_id] =&gt; 2270 [sku] =&gt; 1DAFPOT5 [qty] =&gt; 23.0000 [is_in_stock] =&gt; 1 ) ) </code></pre> <p>Am I constructing the variable incorrectly or do I need to feed it to the array differently?</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.
 

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