Can I Use Array_push On A SESSION Array In Php?


Answer :

Yes, you can. But First argument should be an array.

So, you must do it this way

$_SESSION['names'] = array(); array_push($_SESSION['names'],$name); 

Personally I never use array_push as I see no sense in this function. And I just use

$_SESSION['names'][] = $name; 

Try with

if (!isset($_SESSION['names'])) {     $_SESSION['names'] = array(); } array_push($_SESSION['names'],$name); 

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable