This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Arrays Forum

View Course » View Exercise

1283 points
259736fdb98343caddd0f941e71ffa3b?s=140&d=retro
Submitted by
John Connolly
over 4 years ago

Replacing PHP with C++ Worked for Me

Bug in the editor for this one but after ages I decided to pick C++ to replace PHP and it managed to work, don't ask me how. The code was always right it was just the printing of the replacement that wouldn't work. Other ones worked for others but didn't work for me so there's no guarantee that this solution will work for everyone but here it is anyway

<?php
$languages = array("HTML/CSS",
"JavaScript", "PHP", "Python", "Ruby");
// Write the code to modify
// the $languages array!
$languages{2} = "C++" ;
print $languages{2};
?>


1 vote

permalink

This worked for me as well. "vba" however would not work but would display just fine in the preview pane.

167 points
597fb53e71b7f9fc28c43ab916a3c765?s=140&d=retro
Submitted by
tss3
over 4 years ago


0 votes

permalink

Worked for me as well
thanks

48 points
51dee2d99c4e9da722000267_74048044
Submitted by
Aman Sahu
about 4 years ago


0 votes

permalink

me too. thanks

Modifying Elements



<?php
$languages = array( 0=>"HTML/CSS",
1=>"JavaScript", 2=>"PHP", 3=>"Python", 4=>"Ruby");

    // Write the code to modify
    $languages [2]="c++";
    // the $languages array!
    echo "$languages[2]";
  ?>
</p>

306 points
51924006b3ee711a31003051_511460194
Submitted by
Hafizi
about 4 years ago


0 votes

permalink

Thank you !
That's amazing !

62 points
2533b9d397c9157dc313055209ac1d41?s=140&d=retro
Submitted by
519291175
about 4 years ago


0 votes

permalink

This also worked for me, apparently HTML5 doesn't

260 points
51fd48ceabf821daf7003479_381656722
Submitted by
The Doctor
about 4 years ago


0 votes

permalink

Thank you,but to me it is not working,and i do not know where it is the error.
<?php
$languages = array("HTML/CSS","JavaScript", "PHP", "Python", "Ruby");
// Write the code to modify
// the $languages array!
$language {2}= "C++";
echo "$language {2}";
?>

290 points
5631023ad3292fc57400021a_214964193
Submitted by
Roman Ina
about 4 years ago


0 votes

permalink

It looks like it is checking that the output is not something that is in the original array instead of the array its self. if you modify the array like so
$languages = array("HTML/CSS", "JavaScript", "PHP", "Python", "Ruby");
$languages[0] = "JavaScript

echo'ing element 0 it appears as incorrect sames goes if you do
$languages = array("HTML/CSS", "JavaScript", "PHP", "Python", "Ruby");
array_push($languages);
echo $languages[0]

Which returns Javascript

However if you do $languages[2] = "HTML is cool" it says this is correct.

418 points
8bddc384be424531d5e9bf595a6e15e5?s=140&d=retro
Submitted by
Josh Carswell
almost 4 years ago


0 votes

permalink

thanks so much

811 points
D55907577da7955ee1fd47c4f5aff645?s=140&d=retro
Submitted by
Paul Crary
over 2 years ago