1

I need to set a variable = to an array element. $var = $ary[1]; does not work. ary[1]= "test". If that helps

3
  • You might need to be more specific about what you're trying to do and the results of what you've tried. $var = $ary[1] is certainly a valid assignment. Commented May 28, 2011 at 5:37
  • hello Dan first echo $ary[1] and see that it is having the value? Commented May 28, 2011 at 5:42
  • Since you are new to stackoverflow, if charlie answered your code correctly please select it as the correct answer Commented May 28, 2011 at 6:08

4 Answers 4

5

PHP arrays are zero indexed, that may be your problem

    $ary = array("test");
    $var = $ary[0]

$var == "test"

Sign up to request clarification or add additional context in comments.

1 Comment

how to use it for $content = array( "en" => $massage );
2

confirm that your first initialize the array variable before using it like:

$ary=array();

Try this:

$ary[]= $var;

must use $ sign for var/arrays in php and you don't require 1 if a single value is inserted..

Comments

0

This is the way to set a variable with array elemen.

why it is not working , please check your array content .

http://php.net/manual/en/language.types.array.php

Comments

0

Try using

$content = array( "en" => "{$massage}" );

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.