2

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(
'Fruitland' => '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'?

2 Answers 2

5

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",
);
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, (that was a quick!) and helpful reply ^_^ EDIT: If you don't mind, I hope I can squeeze in another PHP question: header("Location: ".$variable.".html") is this legal? Doing a concatenation like this?
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.