Page 1 of 1

new to php, array question

Posted: Mon Aug 27, 2012 9:45 pm
by 850t
Have put aside php in the last decade and now I've to pick that up again. I have a very simple question to ask.

I'm trying to move an array to another array by using a loop and a function. I wonder why when I do print_r the array, nothing gets print?

Below is my sample code.

Code: Select all

<?php

$All = array();

$ID_list = array("1", "2", "3");

foreach($ID_list as $ID) {
echo $ID . "<BR>";
	subFunc($ID);
}

print_r($ALL);

function subFunc($ID) {
	global $All;
	$All[] = $ID;		
}

?>

Re: new to php, array question

Posted: Mon Aug 27, 2012 10:17 pm
by Benjamin

Code: Select all

$ID_list = array("1", "2", "3");

$All = $ID_list;
?

Re: new to php, array question

Posted: Wed Aug 29, 2012 3:35 pm
by Live24x7
How we complicate our lives :lol:

Re: new to php, array question

Posted: Sun Sep 09, 2012 11:21 am
by McInfo

Code: Select all

$All = array();
print_r($ALL);
$ALL is not $All.