...

View Full Version : whts wrong with this Code..



ajloun
08-28-2009, 04:25 AM
Hello

i have this code Bellow . where i want the Value of $all to be filed under Value $do .


$all= "1", "2", "3", "yes", "no", "off", "sure", "ok", "mode", "or";
$do = array("$all");

whts wrong in that Code ..

PS : i do not want the Values be direct under do like

$do = array("1", "2", "3", "yes", "no", "off", "sure", "ok", "mode", "or");

i know that works but i do not want use it that way to avoid duplicate

Mwnciau
08-28-2009, 04:32 AM
Is $do an empty array at the start? If so then just do it the second way, if not try this:


array_push($do, "1", "2", "3", "yes", "no", "off", "sure", "ok", "mode", "or");


Edit: do you mean you want to create an array with no duplicate entries? If so take a look at the array_unique (http://uk2.php.net/manual/en/function.array-unique.php) function

Fou-Lu
08-28-2009, 04:38 AM
First, fix up that $all, it should be a complete string:


$all= '"1", "2", "3", "yes", "no", "off", "sure", "ok", "mode", "or"';

Once fixed, use explode:


$do = explode(', ', $all);

All done.

ajloun
08-28-2009, 04:44 AM
umm Maybe i was not Clear ..

I want the Valuse of $all fill as is in the $do

i tried this.

$all="1,2,3,4,on,yes";
$do=explode(",",$all);

but didt work , show no error thu

ajloun
08-28-2009, 04:47 AM
i answered before read Fou answer , I tried that but for some reason the value of $all won't be in do when do ur way ..

Fou-Lu
08-28-2009, 04:51 AM
Hello

i have this code Bellow . where i want the Value of $all to be filed under Value $do .


$all= "1", "2", "3", "yes", "no", "off", "sure", "ok", "mode", "or";
$do = array("$all");

whts wrong in that Code ..

PS : i do not want the Values be direct under do like

$do = array("1", "2", "3", "yes", "no", "off", "sure", "ok", "mode", "or");

i know that works but i do not want use it that way to avoid duplicate

You specified that you want each of the items in the string $all to be an item in array $do.
If you just want it to be a single offset in $do, than you can use:


$all= '"1", "2", "3", "yes", "no", "off", "sure", "ok", "mode", "or"';
$do = (array)$all;

ajloun
08-28-2009, 05:04 AM
Ok Sorry for not been Clear , i will try again my Best Now i have This Code .

$do= array("1", "2", "3", "yes", "no", "off", "sure", "ok", "mode", "or");

I do not want keep write this Code when every needed so i Need it look like

$all= array("$do");

where $all Means the valuse "1","2"....etc

wht is the right way to do it

Fou-Lu
08-28-2009, 09:39 AM
Than its explode you want:


$all = "1,2,3,4,on,yes";
$do = explode(',', $all);
print_r($do);

Results:


Array
(
[0] => 1,
[1] => 2,
[2] => 3,
[3] => 4,
[4] => on,
[5] => yes
)

ajloun
08-28-2009, 10:03 AM
Thx Fou .. i went with the other Soluation you Gave me first



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum