0

what I have to change to this part will work?

$array4Midfeld = array('$LM', '$DMEins', '$DMZwei', '$RM');
$array4Midfield[0] = "Test";

At the moment I get an error, regarding to the second line. Error is... $LM not defined.

1
  • Your code copied verbatim as above, does not give me any errors. Is this the code that produces the error you describe? Can you please include the full error message. Commented Sep 9, 2017 at 13:48

3 Answers 3

1

There is spelling mistake in array name on line number 2. You have created array with $array4Midfeld name and accessing it with $array4Midfield name on line number 2. That's why you are getting error. try following code, It is working.

<?php
$array4Midfield = array($LM, $DMEins, $DMZwei, $RM);
$array4Midfield[0] = "Test";

print_r($array4Midfield);
?>
Sign up to request clarification or add additional context in comments.

2 Comments

I think ' should not be there (because all are variables there). i removed it. Correct it if i am wrong.
Your suggestion is right @AlivetoDie he want to store value of $LM and all other variables, but as in the code he did not define all variables so I thought he wants to store $LM and all as it is with $ sign, if this is the case then my code was right.
1

You have two problems with this:

  1. Are you assigning variables as elements of the array? (ie $LM, $DMZwei, etc), or are they text? "$LM", "$DMZwei"

  2. Your variables are not the same. Line 1 and Line 2 are two different vars: array4Midfeld and array4Midfield, are they supposed to be the same?

So are you testing that

`$array4Midfield[0] = "Test"

or

`$array4Midfield[0] = $LM

or

$LM = "Test"

Comments

0

Please assign Values to an array in this form. More over the array name too, am confuse whether they are the same or not. $array4Mittelfeld or $array4Midfield

$array4Mittelfield[0] = $LM;

$array4Mittelfield[1] = $DMEins;

$array4Mittelfield[2] = $DMZwei;

$array4Mittelfield[3] = $RM;



echo $array4Mittelfield[0];

or you can use loop to print all the values

Hope it helps

Comments

Your Answer

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