new to php, array question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
850t
Forum Newbie
Posts: 1
Joined: Mon Aug 27, 2012 9:40 pm

new to php, array question

Post 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;		
}

?>
Last edited by Benjamin on Mon Aug 27, 2012 10:15 pm, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: new to php, array question

Post by Benjamin »

Code: Select all

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

$All = $ID_list;
?
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

Re: new to php, array question

Post by Live24x7 »

How we complicate our lives :lol:
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: new to php, array question

Post by McInfo »

Code: Select all

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