Dan
Dan

Reputation: 1447

Set variable to array element

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

Upvotes: 1

Views: 22664

Answers (4)

Nihas TM
Nihas TM

Reputation: 1

Try using

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

Upvotes: 0

Vaibhav Gupta
Vaibhav Gupta

Reputation: 1612

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..

Upvotes: 2

charlie
charlie

Reputation: 89

PHP arrays are zero indexed, that may be your problem

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

$var == "test"

Upvotes: 5

XMen
XMen

Reputation: 30238

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

Upvotes: 0

Related Questions