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

 

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?

I believe the extract() function is what I needed. Just discovered it.

All the index names are the datatable column names and extract()

fills in the variables automatically.... just what I needed.

 

http://www.hudzilla.org/phpbook/read.php/5_0_0

 

This url I discovered really helped me work through

through this problem.

 

eatc7402

Archived

This topic is now archived and is closed to further replies.

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