Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing an Empty Value of Array and Counts the value inside it.
    primarykey
    data
    text
    <p>I have this certain code that checks if a variable is <strong>not empty</strong> if it is not empty it will merge in an array that "has" a value in it. if it is empty it will merge in an array but passing "no values or any other stuff even null values"</p> <p>Here my code for it.</p> <pre><code>$fb_description_arr[] = ($page_desc != "") ? $page_desc : array(); $fb_share_arr[] = ($share_link != "") ? $share_link : array(); $tweet_arr[] = ($twitter_link != "") ? $twitter_link : array(); $follow_arr[] = ($twitter_follow != "") ? $twitter_follow : array(); $site_link_arr[] = ($site_link != "") ? $site_link : array(); </code></pre> <p>Let's say <strong>$page_desc is not null</strong>, and has a value of "This is me" and the <strong>rest of the variables are null</strong></p> <pre><code>$test_arr = array_merge($fb_description_arr, $fb_share_arr, $tweet_arr, $follow_arr, $site_link_arr); print_r($test_arr); </code></pre> <p>so I tried to debug and show the merged array on it. that will be shown below.</p> <p><strong>Array ( [0] => This is me[1] => Array ( ) [2] => Array ( ) [3] => Array ( ) [4] => Array ( ) )</strong></p> <p>So if I count it up using the count() function in php </p> <pre><code>$total_raffle = count(array_merge($fb_description_arr, $fb_share_arr, $tweet_arr, $follow_arr, $site_link_arr)); </code></pre> <p>Obviously, it will show an output of <strong>"5"</strong></p> <p>What solutions I've tried in ternary operator to pass an empty value that will not be counted in count() function.</p> <ol> <li>array()</li> <li>null</li> <li>false</li> <li>""</li> </ol> <p>So my desired output is <strong>"1"</strong> since <strong>$page_desc is the only variable that has value in it</strong> and the rest doesn't have any value</p> <p>Any solutions for this stuff?</p> <p>A help would be appreciated. :)</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.
    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