Forum Moderators: coopster

Message Too Old, No Replies

array input and output

         

Flolondon

10:03 am on Mar 26, 2006 (gmt 0)

10+ Year Member



I notice that most diagrams give the coding of arrays but they dont give the user input side of things... so that one can get a holistic view of the forefront, middle and backend of arrays...

Say for example.. I had an array of plants. and then added a foreach loop to it.

How would the user input ( what methods- i need to see input examples_ to retrieve the information. sorry a bit confused..

$names[] = 'David';
$names[] = 'Marty';
$names[] = 'Debbie';
$names[] = 'Munchkin';
$names[] = 'Fluffy';

With the above, how does a user input which ones they like.. i hope i am explaining myself properly..

RonPK

12:26 pm on Mar 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure whether I understand what you mean, so forgive me if I'm saying something too obvious.

To add an element to an array:

$names[] = 'Jack';

or

array_push($names, 'Jack');

To retrieve an element from an array:

$value = $names[2];

To retrieve the key of the element with value 'Jack':

$key = array_search('Jack', $names);

Flolondon

12:46 pm on Mar 26, 2006 (gmt 0)

10+ Year Member



thanks.... but i was talking more in terms of the actual user.. visually from a user side...

RonPK

2:37 pm on Mar 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't get it. Maybe you could explain what kind of application you're building, and what you want to use the array for.

Flolondon

4:43 pm on Mar 26, 2006 (gmt 0)

10+ Year Member



ok... i would like to see the HTML version from the user prospective... to get an idea of the whole script...thanks..

ok for example.

<?php $dy = array ("21st ", "22nd ", "23rd ");
$mo = array ("Jan ", "Feb" ,"Mar ") ;
$yr = array ("2002", "2003", ","2004");

echo ($dy [ ].$mo [ ].$yr [ ]);

?>

If i wanted to do a HTML script for the above... what would could it look like to the user...

In order to help me understand arrays properly, i need to see how the user would see what to input and how the variable of the array would be presented to the user.

RonPK

6:15 pm on Mar 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Arrays are not much more than a way to store data during the execution of a script. Arrays are not presented to the user.

Flolondon

6:30 pm on Mar 26, 2006 (gmt 0)

10+ Year Member



ok thanks...so it means that arrays are just a means of having a fancy script behind the scenes but the output is just as static as word document.

Some of the output could just as well be written in HTML