For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > January 2007 > Index and Array problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Index and Array problem
Louie Miranda

2007-01-25, 10:01 pm

Is it possible to manipulate the index of an array?

my code..

initialize the arrays..

$secondary = array();
> $secondary[1] = array();
> $secondary[2] = array();
> $secondary[3] = array();
>


query the database

$fedex =& $db->query('SELECT * from scalc_zone_fedex order by country'); //
> has id and country fields
> while ($row_fedex = $fedex->fetchRow(MDB2_FETCHMODE_ASSOC)) {
> //echo $row['country'] . "\n";
> //$secondary[1] = $row['country'];
> array_push($secondary[1], $row_fedex['country']);
> }
>


print $secondary array

print_r($secondary)
>


result of the array

> [1] => Array
> (
> [0] => Afghanistan
> [1] => Albania
> [2] => American Samoa
> [3] => Andorra
> [4] => Angola
> [5] => Anguilla
>
> [6] => Antigua
> [7] => Argentina
> [8] => Armenia
> [9] => Aruba
> [10] => Australia
> [11] => Austria
> [12] => Azerbaijan
>
> [13] => Bahamas
> [14] => Bahrain
> [15] => Bangladesh
> [16] => Barbados
> [17] => Belarus
> [18] => Belgium
> [19] => Belize
>
> [20] => Benin
>
> )
>
>

Now, the problem i got is. The index should not start from 0 to 20. What i
was thinking is get the field id $row_fedex['id'] and display the result of
the id as the index. But, i am quite lost already. How can i do that?

I've tried editing this one..

array_push($secondary[1], $row_fedex['country']);
>
> into
>
> array_push($secondary[1].$row_fedex['id'], $row_fedex['country']);
>


But its all wrong..

PHP Fatal error: Only variables can be passed by reference

Please help!
--
Louie Miranda ( lmiranda@gmail.com)
http://www.axishift.com

//JSM-W

Paolo Sala

2007-01-26, 4:01 am

Louie Miranda scrisse in data 26/01/2007 03:27:[color=darkred]
Have you tried
$secondary[1][$row_fedex['id']]=$row_fed
ex['country'];

Have a great day

Piviul
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com