开发者

Using the apostrophe for PHP associative array element's name

开发者 https://www.devze.com 2022-12-31 21:21 出处:网络
Hi I\'ve been trying to figure out how to put something likeJoe\'s Fruits into a PHP array something like this:

Hi I've been trying to figure out how to put something like Joe's Fruits into a PHP array something like this:

<?php
$arr = array(
'Fruitl开发者_如何学Goand' => '3ddlskdf3',
'Joe's Fruits' => 'dddfdfer3',
);
?>

Using the above for example (stackoverflow's code color should tell you this by now), the array will take it as 'Joe' between the two apostrophes instead of the whole 'Joe's Fruits' is there any way I can do this without just calling it 'Joes Fruits'?


Escape quotes with a backslash (\):

<?php
$arr = array(
'Fruitland' => '3ddlskdf3',
'Joe\'s Fruits' => 'dddfdfer3',
);
?>

You can also simply do:

<?php
$arr = array(
"Fruitland" => "3ddlskdf3",
"Joe's Fruits" => "dddfdfer3",
);
?>


PHP strings manual is very useful for ones who just started to learn.
Along with strings functions list it covers half of the necessary knowledge.

0

精彩评论

暂无评论...
验证码 换一张
取 消