是否可以在PHP中的数组中定义变量字段名称?

i need to push values in an array, but this array is always with different number of elements, and some of them are numbered i would like to have something like:

{"idWeb":223,"category":"animals","questionText":"have you got animals?","howManyAnswers":2,"answerText1":"yes","risid1":43,"answerText2":"no","risid2":44}

for this array, for example the variable names should be answertext1 and answertext2.

so at a time, i will have something like this:

$arrayname['answertext'.$a] = "some sentence string";

is it right?

Yes its correct.. For example

$arr = array( 'a1'=>12,'a2'=>32,'a3'=>22,'a3'=>33 );
$x=1;
print_r($arr['a'.$x]);

This will output 12.

Yes, there's no problem using vars as key names in associative arrays in PHP, for example:

$a = 1;
$b = 2;

$arrayname['answertext'.$a] = "some sentence string A";
$arrayname['answertext'.$b] = "some sentence string B";

echo $arrayname['answertext'.$a] . "<br/>"; //"some sentence string A"
echo $arrayname['answertext1'] . "<br/>"; //"some sentence string A"

echo $arrayname['answertext'.$b] . "<br/>"; //"some sentence string B"
echo $arrayname['answertext2'] . "<br/>"; //"some sentence string B"

To create an associative array with array( ), use the => symbol to separate indexes from values:

$array = array(
    "foo" => "bar",
    "bar" => "foo",
);

// a partir de PHP 5.4
$array = [
    "foo" => "bar",
    "bar" => "foo",
];

To construct an empty array, pass no arguments to array( ):

$addresses = array(  );

More info about arrays: http://oreilly.com/catalog/progphp/chapter/ch05.html