LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-30-2011, 09:04 PM   #1
LionOfGod
LQ Newbie
 
Registered: Mar 2011
Location: Ontario
Posts: 26

Rep: Reputation: 0
PHP Accesing variables within an array


Hello,
Im pretty new to PHP so excuse my dumbness
I've searched this up in quite a few places and cant find anything : (
Basically, I've made an array, within it are 3 more arrays
Their are two values in each array, 'Name' and 'Age'
Basically Im using a While statement to try and cycle through the 'age' value of my array and state whether or not the person is eligible.
(Im actually just learning so I'm doing this to just test myself)
Here is my code
Code:
<?php 
$people =array(
array('name' => 'Bob', 'age' => 15 ),
array('name' => 'Jhon' , 'age' => 10),
array('name' => 'Sue' , 'age' => 7));
//($value =& $people[0,1,2][age] ); Here was an attempt to try and create a reference to age, i tried it many different ways
while($age < 10) {
echo ('$name, is elligible')
	;
}

?>
Okay, so I tried to do this through two ways, one way i tried to create a reference to age, then evaluate it, without that line of code their would be no reference, which way is correct, why wont it work?
Im using Xammp, so when i launch local host I get an undefined variable error
What To Do?
 
Old 03-30-2011, 09:23 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
PHP Code:
foreach ($people as $person) {
  if (
$person['age'] < 10){
    do 
something
  
}

jlinkels
 
1 members found this post helpful.
Old 03-30-2011, 09:28 PM   #3
LionOfGod
LQ Newbie
 
Registered: Mar 2011
Location: Ontario
Posts: 26

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jlinkels View Post
PHP Code:
foreach ($people as $person) {
  if (
$person['age'] < 10){
    do 
something
  
}

jlinkels
TyVM : D
BUT...
Sorry, i didnt state this before, how do i refer to the certain persons name?
As in, if the person is "elligible" how do i refer to them by name in an echo statement?
 
Old 03-31-2011, 05:43 AM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
PHP Code:
foreach ($people as $person) { 
  if (
$person['age'] < 10){ 
     echo 
"{$person['name']} is still young";
  } 

jlinkels
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Server array (mysql, php) -> gboolean array in c client kalleanka Programming 1 07-27-2010 06:50 AM
bash: use file as input into array, parse out other variables from array using awk beeblequix Linux - General 2 11-20-2009 10:07 AM
PHP: Converting a PHP array into an HTML array koosha Programming 4 08-11-2009 08:47 AM
Adding array variables together nobody123 Linux - Newbie 2 02-26-2009 04:43 PM
BASH - Array Variables Micro420 Programming 5 12-15-2006 05:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration