Jump to content

arrays simple question


Guest Cashster09

Recommended Posts

Guest Cashster09

i have uploaded this to my server and it worked but wondered why?

I didnt use quotes around the names ["Bob"] and it still output

 

The salary of Bob is $1000

 

I know you dont need quotes around the numeric values of 1000, 2000, and 3000 but i thought u did around the names in brackets. I'm new at this....

 

<?php

 

 

$salaries [bob] = 1000;

$salaries [Rich] = 2000;

$salaries [John] = 3000;

 

echo "The salary of Bob is $" . $salaries [bob];

 

?>

Link to comment
Share on other sites

$this_variable = "This Variable";
echo "This part " . $this_variable . " and another part. 
";
echo 'This part ' . $this_variable . ' and another part. 
';
echo "This part  $this_variable  and another part. 
";
?>

The example you have uses the concatenation operator, like the first and second example I posted.

The Third line above has the variable embedded inside double quotes, which gets parsed as the variable contents. The echo with single quotes do not get parsed as php code, so it actually runs quicker on the Server.

Also, to ensure that your code will work on more Servers without difficulties, I suggest that you add the single quotes inside the square Array brackets.

$salaries ['Bob'];

Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...