| | |
Array within an array
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
php Syntax (Toggle Plain Text)
$somearray = array( array('a' => 'Hello'), array('b' => 'World') ); echo $somearray[0]['a'] . ' ' . $somearray[1]['b']; // Hello World
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
php Syntax (Toggle Plain Text)
<?php // Set array parts $a = array("1" => "one", "2" => "two"); $b = array("a" => "aye", "b" => "bee"); $c = array("a scalar", $a, $b); // Extract a sub-element from an array in the array $d = $c[1][2]; // Extract a sub-array from the array $e = $c[2]; // Display the various demonstration bits print "<pre>\n\$c[2] = "; print_r ($c[2]); print "</pre>\n\n"; print "\$c[2]['b'] = {$c[2]['b']}<br>\n\n"; print "<pre>\n\$c[1] = "; print_r ($c[1]); print "</pre>\n\n"; print "\$d = $d<br>\n\n"; print "<pre>\n\$e = "; print_r ($e); print "</pre>\n\n"; print "\$c[0] = $c[0]<br>\n"; ?>
Watch the syntax when printing. PHP's parser is a little dicey in that situation; arrays often need to be braced when printing directly.
•
•
Join Date: Jan 2009
Posts: 22
Reputation:
Solved Threads: 0
thanks for the advice
so using the first example:
if [0] had [a][b][c]
all i'd need to do to access an array and assign the contents to vars would be (using first example):
so using the first example:
if [0] had [a][b][c]
all i'd need to do to access an array and assign the contents to vars would be (using first example):
PHP Syntax (Toggle Plain Text)
$avar = $somearray[0]['a']; $bvar = $somearray[1]['b']; echo $avar; echo $bvar; // Hello // World
•
•
•
•
thanks for the advice
so using the first example:
if [0] had [a][b][c]
all i'd need to do to access an array and assign the contents to vars would be (using first example):
PHP Syntax (Toggle Plain Text)
$avar = $somearray[0]['a']; $bvar = $somearray[1]['b']; echo $avar; echo $bvar; // Hello // World
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
![]() |
Similar Threads
- 2D array to 1D array vice versa?? (VB.NET)
- accessing 2d array as 1d array (C++)
- copying single array to 2D array (C++)
- Array/String intersect and Array/Array intersect code (C#)
- passing values from array to array (C)
Other Threads in the PHP Forum
- Previous Thread: Standard Error Showing
- Next Thread: BCC Email Action
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube






