confused on arrays

confused on arrays

am 03.11.2007 21:32:23 von JA

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!

Re: confused on arrays

am 03.11.2007 22:39:27 von Shion

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

Re: confused on arrays

am 03.11.2007 22:58:37 von JA

"J.O. Aho" wrote in message
news:5p484gFp9fppU2@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

Re: confused on arrays

am 03.11.2007 23:06:28 von Michael Fesser

..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

Re: confused on arrays

am 03.11.2007 23:40:38 von JA

> 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

Re: confused on arrays

am 04.11.2007 07:37:22 von Shion

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

Re: confused on arrays

am 05.11.2007 19:45:44 von unknown

Post removed (X-No-Archive: yes)

Re: confused on arrays

am 06.11.2007 09:00:44 von David Quinton

On 5 Nov 2007 10:45:44 -0800, Tom 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
";
}

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:
Great gifts:

Re: confused on arrays

am 06.11.2007 20:32:35 von unknown

Post removed (X-No-Archive: yes)