arrays problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Bomas
Forum Newbie
Posts: 24
Joined: Sun Oct 17, 2004 2:41 am
Location: Heverlee, Belgium

arrays problem

Post by Bomas »

i have made a script containing two arrays. Now i wonna merge those two together in one single array. here's my code:

Code: Select all

$search= array( "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", 
			"S", "T", "U",  "V", "W", "X", "Y", "Z");
			
for($b=0; $b<26; $b++){
$all[$b]= substr_count($string, $search[$b]);
}
$ar1= array( "$all[0]" => "$search[0]", "$all[1]" => "$search[1]", "$all[2]" => "$search[2]", "$all[3]" => "$search[3]",
			 "$all[4]" => "$search[4]", "$all[5]" => "$search[5]", "$all[5]" => "$search[5]", "$all[6]" => "$search[6]",
			 "$all[7]" => "$search[7]", "$all[8]" => "$search[8]", "$all[9]" => "$search[9]", "$all[10]" => "$search[10]",
			 "$all[11]" => "$search[11]", "$all[12]" => "$search[12]", "$all[13]" => "$search[13]", "$all[14]" => "$search[14]",
			 "$all[15]" => "$search[15]", "$all[16]" => "$search[16]", "$all[17]" => "$search[17]", "$all[18]" => "$search[18]",
			 "$all[19]" => "$search[19]", "$all[20]" => "$search[20]", "$all[21]" => "$search[21]", "$all[22]" => "$search[22]",
			 "$all[23]" => "$search[23]", "$all[24]" => "$search[24]","$all[25]" => "$search[25]");
arsort($all);
ksort($ar1);

$switch= array_flip($all);
print_r($switch);

$sw= array_values($switch);

$srch= array( "$search[$sw[0]]", "$search[$sw[1]]", "$search[$sw[2]]", "$search[$sw[3]]", "$search[$sw[4]]",
			"$search[$sw[5]]", "$search[$sw[6]]", "$search[$sw[7]]", "$search[$sw[8]]", "$search[$sw[9]]", 
			"$search[$sw[10]]", "$search[$sw[11]]", "$search[$sw[12]]", "$search[$sw[13]]", "$search[$sw[14]]",
			"$search[$sw[15]]", "$search[$sw[16]]", "$search[$sw[17]]", "$search[$sw[18]]", "$search[$sw[19]]",
			"$search[$sw[20]]", "$search[$sw[21]]", "$search[$sw[22]]", "$search[$sw[23]]", "$search[$sw[24]]",
			"$search[$sw[25]]");
now when i test my script it returns an error:

Code: Select all

Parse error: parse error, unexpected '&#1111;', expecting ']' in /opt/www/cofadmin/web/www.cities-of-faith.com/code2.php on line 79
the code on line 79 is that one from $srch= array( ..... );

now, i don't know what i'm doing wrong, but can anybody help me?

thx allready


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

nesting variables in a string requires complex syntax

Code: Select all

$srch = array(&quote;{$search&#1111;$sw&#1111;0]]}&quote;);
Although, if they are strings already, why not just remove the double quotes?
Post Reply