0
$array_1 = array(
    'name' => 'Example Name',
    'company' => 'Intel ',
    'website' => 'WWW.intel.COM',
    'contact' => 'CONTACT@intel.COM',
    'twitter' => 'HTTP://TWITTER.COM/intel',
);

$array_2 = array(
    0 => array(
        'id' => '1',
        'field' => 'name',
        'default_field_text' => 'Name Here'
    ),
    1 => array(
        'id' => '3',
        'field' => 'company',
        'default_field_text' => 'COMPENY NAME HERE'
    ),
    2 => array(
        'id' => '4',
        'field' => 'website',
        'default_field_text' => 'WWW.WEBSITECOMPENY.COM'
    ),
    3 => array(
        'id' => '5',
        'field' => 'contact',
        'default_field_text' => 'CONTACT@COMPENY.MAIL.COM'
    ),
    4 => array(
        'id' => '6',
        'field' => 'twitter',
        'default_field_text' => 'HTTP://TWITTER.COM/NAME HERE'
    ),
    5 => array(
        'id' => '8',
        'field' => 'facebook',
        'default_field_text' => 'HTTP://FACEBOOK.COM/YOURNAME'
    )
);

嗨..首先对我的英语感到抱歉...这就是我想要弄清楚的, array_1键被视为字段和表单后值,array_2具有字段 + 默认值..

所以我试图像这样输出

Example Name
Intel
WWW.intel.COM
CONTACT@intel.COM
HTTP://TWITTER.COM/intel
HTTP://FACEBOOK.COM/YOURNAME //from array_2 value

我的代码在这里,但它不起作用..我知道我做错了

foreach($array_2 as $item){
    $text = $item['default_field_text'];
    if($array_1[$item['field']] == $item['field']) $text = $array_1[$item['field']];
    echo $text;
}
4

1 回答 1

0

尝试使用:

if( x === y)

代替:

if(x == y)
于 2012-08-21T10:01:26.420 回答