Modifying Array Elements


#1

Can someone please check my work and tell me what is wrong here?
Instead of "Ruby", the output should be "jQuery" but I get both; RubyjQuery.

<html>
  <head>
    <title>Modifying Elements</title>
  </head>
  <body>
    <p>
      <?php
        $languages = array("HTML/CSS",
        "JavaScript", "PHP", "Python", "Ruby");
        
        echo $languages[4];
        
        $languages[4]="jQuery";
        
        echo $languages[4];
        
      ?>
    </p>
  </body>
</html>

#2

remove the first echo $languages[4] part of your code and try again :sunglasses:


#3

still its not working :cold_sweat:


#4

@chaudharynehadingrag
I think your code should look like this when you remove the echo $languages[4]; above $languages[4]="JQuery;";

<html>
  <head>
    <title>Modifying Elements</title>
  </head>
  <body>
    <p>
      <?php
        $languages = array("HTML/CSS",
        "JavaScript", "PHP", "Python", "Ruby");
        // Write the code to modify
        // the $languages array!
$languages[4] = "SQL";
echo $languages[4];
      ?>
    </p>
  </body>
</html>

Hope this helped


#5

Had the same issue when trsing to change "Python" to "python sucks".
Now I took a completly different value "this is buggy" and it worked.
Guess there is a Ppoblem when the new value starts with the old one.


#6

QUESTION : can array elements be more than one word, like strings?

I.E ;

$languages = array ("one", "two", "three", "four and five") ??


#8

@cleanthoproper
Yeah, except your and is not valid inside an array, put a comma instead. :wink:


#9

i see! thank you.. what is one of my array values is like so:

"I'm learning it!"

I only ask because I tried to use it to modify an array on one of the exercises and it did not let me continue.

thanks for your response!


#10

the issue is that you can't put a existing element form the array, try something different


#11

@gigajumper58194

What do you mean?