confused on arrays

I'm learning php and I'm already stuck on arrays :(

I don't know if I'm getting information overload or what, but I'm really
confused on square brackets vs. parethesis. I see them used almost
interchangedly (if that's a word??) and I'm really having a problem grasping
when to use which on arrays. Is there a simple explanation when one is used
in arrays and when the other is suppose to be used? I first thought that
square brackets are used when assigning a value but then further reading I
see that's not so.


thanks for any enlightenment!
JA [ Sa, 03 November 2007 21:32 ] [ ID #1861671 ]

Re: confused on arrays

ja wrote:
> I'm learning php and I'm already stuck on arrays :(
>
> I don't know if I'm getting information overload or what, but I'm really
> confused on square brackets vs. parethesis. I see them used almost
> interchangedly (if that's a word??) and I'm really having a problem grasping
> when to use which on arrays. Is there a simple explanation when one is used
> in arrays and when the other is suppose to be used? I first thought that
> square brackets are used when assigning a value but then further reading I
> see that's not so.

Simply:

$array[]

function()

--

//Aho
Shion [ Sa, 03 November 2007 22:39 ] [ ID #1861672 ]

Re: confused on arrays

"J.O. Aho" <user [at] example.net> wrote in message
news:5p484gFp9fppU2 [at] mid.individual.net...
> ja wrote:
>> I'm learning php and I'm already stuck on arrays :(
>>
>> I don't know if I'm getting information overload or what, but I'm really
>> confused on square brackets vs. parethesis. I see them used almost
>> interchangedly (if that's a word??) and I'm really having a problem
>> grasping
>> when to use which on arrays. Is there a simple explanation when one is
>> used
>> in arrays and when the other is suppose to be used? I first thought that
>> square brackets are used when assigning a value but then further reading
>> I
>> see that's not so.
>
> Simply:
>
> $array[]
>
> function()
>
Ah. I don't think I got to functions yet. So are you saying that to use the
brackets is only with an existing variable
Sorry I don't understand.

Thanks
JA [ Sa, 03 November 2007 22:58 ] [ ID #1861673 ]

Re: confused on arrays

..oO(ja)

>Ah. I don't think I got to functions yet. So are you saying that to use the
>brackets is only with an existing variable
>Sorry I don't understand.

The brackets are used to access a particular element of an array or a
character in a string.

Micha
Michael Fesser [ Sa, 03 November 2007 23:06 ] [ ID #1861674 ]

Re: confused on arrays

> The brackets are used to access a particular element of an array or a
> character in a string.
>
> Micha

So the bracket is used only when I need to access whatever is contained in
the array while parents are used to construct them? Do I have it somewhat
correct?

thx
JA [ Sa, 03 November 2007 23:40 ] [ ID #1861675 ]

Re: confused on arrays

ja wrote:
>> The brackets are used to access a particular element of an array or a
>> character in a string.

> So the bracket is used only when I need to access whatever is contained in
> the array while parents are used to construct them? Do I have it somewhat
> correct?

No, not only,

assign new values to an array

$array[]='somthing';

which is equal to (using the functions array_push())

array_push($array,'something');


and of course you can access the content on an array by specifying a cell

echo $array[0];

keep in mind that in an array, 0 is the first cell and 1 is the second one.


--

//Aho
Shion [ So, 04 November 2007 07:37 ] [ ID #1862149 ]

Re: confused on arrays

Post removed (X-No-Archive: yes)
Notifier Deamon [ Mo, 05 November 2007 19:45 ] [ ID #1862886 ]

Re: confused on arrays

On 5 Nov 2007 10:45:44 -0800, Tom <tom [at] to.com> wrote:

>You can use numeric values in the brackets to create a scalar array...
>
>$array[0] = 'first';
>$array[1] = 'second';
>
>of you can create associative arrays for key/value pairs, such as ...
>
>$array['age'] = 18;
>$array['date'] = '2007-11-05';
>
>Depending on your application, one may be more useful that the other.

When my brain starts to hurt, I like to do a:
foreach ($myarray as $key=>$value){
echo "KEY: $key - VALUE: $value<br>";
}

for 2 dimensional arrays - which often helps me see what's going on.

3 dimensional ones - now that's where the fun really starts! You can
even mix associative with scalar:
$array['age'][7] etc!

http://www.informit.com/articles/article.aspx?p=31840&seqNum =4&rl=1
seems like quite a good Primer?
--
Locate your Mobile phone: <http://www.bizorg.co.uk/news.html>
Great gifts: <http://www.ThisBritain.com/ASOS_popup.html>
David Quinton [ Di, 06 November 2007 09:00 ] [ ID #1863874 ]

Re: confused on arrays

Post removed (X-No-Archive: yes)
Notifier Deamon [ Di, 06 November 2007 20:32 ] [ ID #1863879 ]
PHP » alt.php » confused on arrays

Vorheriges Thema: Include(filename.php) and security
Nächstes Thema: SOAP Client header