Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In my opinion, to get the most value out of <code>Set::extract</code>, it would be better to start with an array with a structure more like the following (otherwise I believe you'd have to run <code>Set::extract</code> inside a loop):</p> <pre><code>$array = array( 'Shipping' =&gt; array( array ( "id" =&gt; 4, "rate" =&gt; 82.50, "pounds" =&gt; 2, "ounces" =&gt; 3, "mailtype" =&gt; "Package", "country" =&gt; "UNITED KINGDOM (GREAT BRITAIN)", "svccommitments" =&gt; "1 - 3 business days", "svcdescription" =&gt; "Global Express Guaranteed (GXG)", "maxdimensions" =&gt; 'Max. length 46", width 35", height 46" and max. length plus girth combined 108"', "maxweight" =&gt; 30 ), array ( "id" =&gt; 6, "rate" =&gt; 82.50, "pounds" =&gt; 2, "ounces" =&gt; 3, "mailtype" =&gt; "Package", "country" =&gt; "UNITED KINGDOM (GREAT BRITAIN)", "svccommitments" =&gt; "1 - 3 business days", "svcdescription" =&gt; "Global Express Guaranteed Non-Document Rectangular", "maxdimensions" =&gt; 'Max. length 46", width 35", height 46" and max. length plus girth combined 108"', "maxweight" =&gt; 70 ) ) ); </code></pre> <p>Now you can use the path syntax for <code>Set::extract()</code> to extract elements that have a maxweight greater than <code>$x</code>.</p> <pre><code>$extracted = Set::extract($array, '/Shipping[maxweight&gt;'.$x.']'); </code></pre> <p>With this data, you can build the array you're looking for using the rates as keys and svcdescription as values using <code>Set::combine()</code>.</p> <pre><code>$combined = Set::combine($extracted, '{n}.Shipping.rate', '{n}.Shipping.svcdescription'); </code></pre>
 

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