Jump to content

What the heck is '=>' as an operator in arrays


eatc7402

Recommended Posts

I feel dumb. I've been having a problem getting informatin OUT of an '

multi-dimensioned array. Research shows many examples thst seem

to use the symbols '=>' as some type of assignment (I think) but

I cannot seem to locate an explanation of what and how the =>

is for and how exactly it is used. I could use a steer.

 

Now for my array problem. I have a five row array. Each row has 20

columns in it - titled with text, so I guess I have an 'associative'

array. A print_r of the array indicates it is organized exactly I would

expect it to be.

 

I am trying to get a SINGLE CELL value assigned to variable

as in $cell_value=$my_array[1]['some_cell']; , however this

does seem to result in the value I can SEE in the print_r

cell for that (row1) value being assigned to the variable.

Dunno what I am doing wrong.

 

BTW I can do a printF on the same $my_array[1]['some_cell'] cell and it does show

the right value. I just don't seem to be able to ASSIGN it to something else.

 

eatc7402

 

Link to comment
Share on other sites

The => operator give a value a "name"

 

There are two kinds of arrays. Associative arrays and numerical arrays.

 

Here is a numerical array:

 

<?php

$num_array = array('happy', 'sad', 'coy');
echo $num_array[0];    // happy
echo $num_array[1];    // sad
echo $num_array[2];    // coy

?>

 

Here is an associative array:

 

<?php

$assoc_array = array('first' => 'happy', 'second' => 'sad', 'third' => 'coy');
echo $assoc_array['first'];        // happy
echo $assoc_array['second'];    // sad
echo $assoc_array['third'];       // coy

?>

 

Do you see what I mean?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.