|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Array() Question
How can I echo Array names?
And if I have "nesting doll" array (Meaning an array within an Array) how do echo those inner Arrays names? I'm full of questions |
|
#2
|
|||
|
|||
|
RE: Array() Question
Do you mean the key values? If so, if you had this:
$myarray = array("First"=>1,"Second"=>2,"Third"=>3); you could do this: foreach($myarray as $key=>$value) { echo "Key name is: $key<BR>n"; echo "Value is: $value<BR>n"; } |
|
#3
|
|||
|
|||
|
RE: Array() Question
try this code. The function here loop through all the elements in an array recursively. so if there is an array in an array in an array etc (you get the idea) this code will echo the names. I wrote it just but I'm sure you can amended if you need to. I have included an example.
Code:
<?php
function echoArray($arrayName)
{
foreach ($arrayName as $arrayElement)
{
if (count($arrayElement) > 1)
{
echoArray($arrayElement);
}
else
{
echo "element value: $arrayElement <br>n";
};
};
};
$intensity = array('luminous','neon');
$shades = array('light','dark',$intensity);
$colors = array('red','blue','green', $shades);
echoArray($colors);
?>
hope that helps |
|
#4
|
|||||
|
|||||
|
RE: Array() Question
These Array within Array, can they be stored to a Database?
php Code:
[0] = >Array as new Row [0] = >Initial as a new Field ...and so on? |
|
#5
|
|||
|
|||
|
RE: Array() Question
don't think you'll be storing arrays in a database. Better for the table to have the necessary fields for the array elements and populate each one when you add the data to the database
|
|
#6
|
|||
|
|||
|
RE: Array() Question
Well the problem with that is if the data is kept for Historical value.
This data for example is storm data. Well, if the storm is named that would be that table. Limited amount of databases is the reason for flatting the data as so. |
|
#7
|
|||
|
|||
|
RE: Array() Question
you should use a relational database setp. Have a table of storm names and a unique id for each as the key. In another table hold the stats. Then for each storm id hold rainfall, windspeed etc on the same row and so keep all the data in that one table and storm names in another.
|
|
#8
|
|||
|
|||
|
RE: Array() Question
Hmm... I think I'm following you...
Can you give an example? So, I see what you mean. |
|
#9
|
|||
|
|||
|
RE: Array() Question
Have a table called storms that looks like:
id | name 1 | Andrew 2 | Mark 3 | Michelle etc then a table called storm_data that looks like: stormid | field1 | field2 | field3 | field4 | field5 1 | 48HR VT | 26/1800Z | 33.8N | 52.0W | 50 KTS etc |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Array() Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|