I have a chunk of PHP code that is giving me an Undefined index message.
$order = explode(',', $ass_icon_order);
foreach($order as $function){
$function = (isset($function) ? $function : null);
if($function != ''){
$css .= '.ass-sortable-li.li-'.$function.' a:hover, .ass-sortable-li.li-'.$function.'.active a { background:'.$colors[$function].' }';
?>
<li id="<?php echo $function; ?>" rel="<?php echo $function; ?>" class="ass-sortable-li li-<?php echo $function; ?>">
<?php echo '<a href="#" class="icon-bg"><i class="ass-'.$function.'"></i></a>'; ?>
</li>
<?php
$count_networks++;
}
}
When I run a print_r($order) I get this array:
Array
(
[0] => twitter
[1] => facebook
[2] => googleplus
[3] => delicious
[4] => stumbleupon
[5] => pinterest
[6] => linkedin
[7] => youtube
[8] => fblike
[9] => fbshare
[10] => fbtalk
[11] => twitter_followers
[12] => twitter_following
[13] => twitter_tweets
[14] => twitter_shares
[15] => google_shares
[16] => google_followers
[17] => linkedin_shares
[18] => linkedin_followers
[19] => delicious_shares
[20] => delicious_followers
[21] => youtube_subscribers
[22] => youtube_views
[23] => dribbble
[24] => soundcloud_followers
[25] => soundcloud_plays
[26] => instagram
[27] => mailchimp
[28] => foursquare
)
When I run print_r($colors) I get:
Array
(
[fblike] => #3b5998
[fbshare] => #3b5998
[fbtalk] => #3b5998
[twitter_followers] => #4ec2dc
[twitter_following] => #4ec2dc
[twitter_tweets] => #4ec2dc
[twitter_shares] => #4ec2dc
[google_shares] => #2d2d2d
[google_followers] => #2d2d2d
[linkedin_shares] => #006da7
[linkedin_followers] => #006da7
[delicious_shares] => #3271cb
[delicious_followers] => #3271cb
[stumbleupon] => #eb4924
[youtube_subscribers] => #df1f1C
[youtube_views] => #df1f1C
[dribbble] => #f175a8
[soundcloud_followers] => #ff4c00
[soundcloud_plays] => #ff4c00
[instagram] => #3b6a91
[mailchimp] => #2C9AB7
[foursquare] => #0732a2
[pinterest] => #d01d15
)
I seem to be getting the notice from this section of code:
$css .= $colors[$function];
I have played around with adding isset, however I don't think I am doing the check correctly.
Any help would be greatly appreciated, thanks
$function = (isset($function) ? $function : null);->$function = (isset($function) ? $function : "");You assigned it with null not empty string$colors[$function]expects each element in$orderto be a key in$colors, but NONE of the$ordervalues you showed are present in$colors. You need to sanitize$orderto make it match up with$colors.if($function != '' && in_array($function, array_flip($colors))), does that do the trick for you?$colorsfortwitter,facebook, etc.