Array Example

Sp!ke 2 Tallied Votes 226 Views Share

This little snippet will teach you all about arrays and arrays of arrays, and so on and so forth.

LastMitch commented: Thanks for sharing! +12
<?php
$foo = array('1' => 'Hello, World!'
                  '2' => 'PHP is the best!'
                  'var' => '');
$foo['var'] = array('1' => 'foo', '2' => 'bar');
//Simple, no? Now...how do we call them?

echo $foo['1'];
// Output: Hello, World!

$i = '2';
echo $foo[$i];
// Output: PHP is the best!

echo $foo['var']['1'] . $foo['var']['2'];
// Ouput: foobar

// I hope this cleared up a lot about arrays for
// you, and how useful they can be, especially
// with a for(); or while(); statement!
?>
Member Avatar for LastMitch
LastMitch

This little snippet will teach you all about arrays and arrays of arrays, and so on and so forth.

Thanks for sharing! I like it. I attached an image of how it looks.

d08405329f7206deb33e08451de2ca28

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.