|
Posted by Rik on 05/20/06 18:11
aqazi@inbox.com wrote:
> while (($record = fgetcsv($userFile, 1000, ",")) !== FALSE)
> {
> array_push($data,$record);
> }
> fclose($userFile);
>
> Now if I want to change the quantity of mango what I have to do. I am
> trying to do something, like this but it's not entirly correct.
>
> foreach($data as $value)
> {
>
> if(((strcasecmp("mango", $value[0]) == 0))
> {
> echo $value[1].NL;
> $data[$value][1] = "1";*
> echo $data[$value][0].NL;
> }
> }
>
> Can anyone give me a hint how can I change the value here.
>
> Any help will be grealty appreciated.
>
> Thanks
> aqazi
It would be easier if you defined keys in your $data array, like:
while (($record = fgetcsv($userFile, 1000, ",")) !== FALSE)
{
$data[$record[0]]= array('color' => $record[1], 'quantity' =>
$record[2], 'price' => $record[3]);
}
fclose($userFile);
(Assuming name is unique)
And then:
$data['mango']['quantity'] = 3;
or
$data['mango']['quantity']++;
whatever you want.
Without changing the array like I said, your code would be like:
foreach($data as $key => $value)
{
if($value[0]=='mango')
{
$data[$key][3] = 'whatever you want quantity to be';
}
}
or write your won array_search_all or array_search_all_recursive function
Grtz,
--
Rik Wasmus
[Back to original message]
|