Forum Moderators: coopster
Array ( [0] => 833759,banana,1/28/2010[1] => 833280,apple,1/28/2010)
1st question: how can i insert an array within the array?
for example:
$myArray = array(orange, blah);
Array ( [0] => 833759,banana,1/28/2010,orange,blah [1] => 833280,apple,1/28/2010,orange,blah)
2nd question: how can i find the array with the match element
for example:
$find = 'banana';
$subject = Array ( [0] => 833759,banana,1/28/2010[1] => 833280,apple,1/28/2010)
if(function($find, $subject , true)
{
echo 'yes find it ';
}
else
{
echo 'no i dont';
}
i really appreciate if you help.
tnx,
nanat.
$fruit_array = array(0 => "Banana", 1 => "Orange", 2 => "Pear");
$taste_array = array(0 => "Yeuch", 1 => "Yum", 2 => "Meh");
$tasty_fruity_array = array_merge($fruit_array, $taste_array); For the second, I believe you could do:
if(preg_match("/banana/", $tasty_fruity_array)) {
echo 'Found it!';
} else {
echo 'It's not there :(';
} EDIT:
Upon re-reading your post, I think what you mean is calling an $array1[0] and it calls everything in array2? In which case:
$fruity_array = array(
0 => array(0 => "Orange", 1 => "Yum"),
1 => array(0 => "Banana", 1 => "Yeuch"),
2 => array(0 => "Pear", 1 => "Meh")
); $fruity_array[0][1] returns "Yum"
$fruity_array[2][0] returns "Pear"
EDIT 2:
Alternativley, as I suspect you really want to do, you could name the array and/or the contents for the description:
$fruity_array = array(
"Banana" => array("Taste" => "Yeuch", "Shape" => "Crescent")
"Pear" => array(0 => "Meh", 1 => "Bell")
"Orange" => array(0 => "Yum", 1 => "Round")
); $fruity_array["Orange"][1] returns "Round"
$fruity_array["Banana"]["Taste"] returns "Yeuch"
This isn't true, you could have:
$somearray = array(
0 => array("Fruit" => "Apple", 739 => "Yummy")
); As for why you would do that... Well, I advise against it to save annoying moments of forgetfulness
EDIT:
typo in my first post, missed commas after the array[array]s in my second example -.-
[edited by: Readie at 5:37 am (utc) on Jan. 28, 2010]
this is my orginal files:
im trying to convert csv to mysql by uploading the csv.
$fp = fopen($uploadfilename ,"r");
$contents = fread($fp, filesize("".$uploadfilename.""));
$newLine = explode("\n",$contents);
$sulod = array($today, $sessionID);
$rows = 1;
i really have big trouble inserting the date and the session id bacause $newLine
result as
Array ( [0] => 833759,banana,1/28/2010[1] => 833280,apple,1/28/2010)
i try array_push(),array_merge() but it doesn't work..
do you think inserting the the session and date would be impossible in that structure of array?
so it would result as
Array ( [0] => 833759,banana,1/28/2010,$today, $sessionID [1] => 833280,apple,1/28/2010,$today, $sessionID)