snipt

Ctrl+h for KB shortcuts
#135203

JavaScript

Wait for array of Deferred (Promises) in jQuery

1
2
3
4
5
var arrayOfDeferredObjects = [ $.ajax('someUrl'), ... ];

$.when.apply($, arrayOfDeferredObjects).then(function() {
    // Do my stuff
});
https://snipt.net/embed/8847e05d1e792920607343481f042ef0/
https://snipt.net/raw/8847e05d1e792920607343481f042ef0/
8847e05d1e792920607343481f042ef0
js
JavaScript
5
2014-07-10T08:33:56
True
False
May 30, 2014 at 02:25 AM
/api/public/snipt/135203/
wait-for-array-of-deferred-promises-in-jquery-71f7153e
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">arrayOfDeferredObjects</span> <span class="o">=</span> <span class="p">[</span> <span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">(</span><span class="s1">&#39;someUrl&#39;</span><span class="p">),</span> <span class="p">...</span> <span class="p">];</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nx">$</span><span class="p">.</span><span class="nx">when</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">$</span><span class="p">,</span> <span class="nx">arrayOfDeferredObjects</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="c1">// Do my stuff</span> </span><span id="L-5"><a name="L-5"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
Deferred, Promise, array, jQuery, wait
#128079

PHP

php array()

1
2
3
4
5
6
7
<?php
	$identity = array(
        		"name" => "Sam",
        		"age"  => "47",
        		"country" => "USA"
                );
?>
https://snipt.net/embed/d69135fcd66db9de96634f01a2c378e4/
https://snipt.net/raw/d69135fcd66db9de96634f01a2c378e4/
d69135fcd66db9de96634f01a2c378e4
php
PHP
7
2014-07-12T13:57:52
True
False
/api/public/snipt/128079/
php-array
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> <span class="nv">$identity</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> </span><span id="L-3"><a name="L-3"></a> <span class="s2">&quot;name&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;Sam&quot;</span><span class="p">,</span> </span><span id="L-4"><a name="L-4"></a> <span class="s2">&quot;age&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;47&quot;</span><span class="p">,</span> </span><span id="L-5"><a name="L-5"></a> <span class="s2">&quot;country&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;USA&quot;</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">);</span> </span><span id="L-7"><a name="L-7"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
array, php
#108547

PHP

Convert Array to Object PHP

1
2
3
<?php

$object = json_decode(json_encode($array), FALSE);
https://snipt.net/embed/e501d688106c3f72b6487363b6e3d0b3/
https://snipt.net/raw/e501d688106c3f72b6487363b6e3d0b3/
e501d688106c3f72b6487363b6e3d0b3
php
PHP
3
2014-07-08T00:38:49
True
True
Jan 26, 2014 at 02:40 AM
/api/public/snipt/108547/
convert-array-to-object-php
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nv">$object</span> <span class="o">=</span> <span class="nb">json_decode</span><span class="p">(</span><span class="nb">json_encode</span><span class="p">(</span><span class="nv">$array</span><span class="p">),</span> <span class="k">FALSE</span><span class="p">);</span> </span></pre></div> </td></tr></table>
array, object, php