Re: Problems with array_push?

From: Date: Tue, 07 May 2013 21:21:30 +0000
Subject: Re: Problems with array_push?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-321026@lists.php.net to get a copy of this message
On Tue, May 7, 2013 at 3:06 PM, Jay Blanchard <jay.blanchard@sigmaphinothing.org> wrote: > I know that I must be missing something really ridiculous, but when I > print_r these arrays they are empty. I have confirmed that $arrayElement is > properly formed, it just seems that array_push is not working. I know I have > done this before, but I cannot find my older code. Can someone clear the mud > from my eyes? > > $issueDifferently = array(); > $issueProblem = array(); > $issueComment = array(); > > function addToArray($id, $namecred, $product, $level, $type, $message) { > $arrayElement = $id > > .'|'.$namecred.'|'.$product.'|'.$level.'|'.$type.'|'.$message; > > if('DoDifferently' == $type) { > array_push($issueDifferently, $arrayElement); > } elseif ('Problem' == $type){ > array_push($issueProblem, $arrayElement); > } elseif ('Comments' == $type) { > array_push($issueComment, $arrayElement); > } > } > print_r($issueDifferently); > print_r($issueProblem); > print_r($issueComment); You have to declare the arrays as global inside your function.

« previous php.general (#321026) next »