How to detect whether a JSON object is a String or an Array in PHP?
<p>When I have an input like below...</p>

<pre><code>{  
     "number":[  
        "+39XXXXXXXX",
        "+34XXXXXXXX",
        "+49XXXXXXXX"
     ],
     "message":"Sample msg..."
}
</code></pre>

<p>I handle it with a <code>foreach</code> loop—like so:</p>

<pre><code>foreach ($message-&gt;number as $key =&gt; $number) {
    ...                                     
}
</code></pre>

<hr>

<p>However when I have an input like this:</p>

<pre><code>{  
     "number": "+49XXXXXXXX",
     "message": "Sample msg..."
}
</code></pre>

<p>I receive an error, cause there is no array to be looped inside the object.</p>

<p><strong>So what is a good and efficient way to detect for this?</strong></p>