PHP Group pointer Assignment related issues

Source: Internet
Author: User
PHP Group Pointer Assignment problem
This post was last edited by Pkkgu on 2014-05-30 09:18:25


$arr =array ();
$arr [' ImagePath ']= ';
$arr [' Size1 ']= ';
$arr [' Imageapath ']= ';
$arr [' Image2path ']= ';
$arr [' Size33 ']= ';
$arr [' Image5path ']= ';
$arr [' Size55 ']= ';
$arr [' Imagebbpath ']= ';
$arr [' Imageccpath ']= ';
$arr [' Size555 ']= ';
$arr [' Imageqqpath ']= ';
$arr [' Image99path ']= ';
$arr [' Imageeepath ']= ';
$arr [' Imageppath ']= ';
$arr [' Size66 ']= ';


$url = '/';
$arr [' ImagePath ']= $url;
$arr [' Imageapath ']= $url;
$arr [' Image2path ']= $url;
$arr [' Image5path ']= $url;
$arr [' Imagebbpath ']= $url;
$arr [' Imageccpath ']= $url;
$arr [' Imageqqpath ']= $url;
$arr [' Image99path ']= $url;
$arr [' Imageeepath ']= $url;
$arr [' Imageppath ']= $url;

------Solution--------------------
What's so weird about that?
And it looks pretty clear.

foreach ($ar as $k =?& $v) if (substr ($k,-4) = = ' Path ') $v = $url;

------Solution--------------------

$arr =array ();
$arr [' ImagePath ']= ';
$arr [' Size1 ']= ';
$arr [' Imageapath ']= ';
$arr [' Image2path ']= ';
$arr [' Size33 ']= ';
$arr [' Image5path ']= ';
$arr [' Size55 ']= ';
$arr [' Imagebbpath ']= ';
$arr [' Imageccpath ']= ';
$arr [' Size555 ']= ';
$arr [' Imageqqpath ']= ';
$arr [' Image99path ']= ';
$arr [' Imageeepath ']= ';
$arr [' Imageppath ']= ';
$arr [' Size66 ']= ';

$url = '/';

foreach ($arr as $key = = $val) {
if (substr ($key, 0,5) = = ' image ') {
$arr [$key] = $url;
}
}

Print_r ($arr);

?>
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.