How to change a value in an array using PHP?
-
I have an array like this: Array ( [error] = Array ( [0] = Password field is required. [1] = Sorry, unrecognized username or password. <a href="/user/password">Have you forgotten your password?</a> ) ) In the above array I need to add an class in the link. My expected output should be like: Array ( [error] = Array ( [0] = Password field is required. [1] = Sorry, unrecognized username or password. <a href="/user/password" class="popups">Have you forgotten your password?</a> ) ) How do I change the array value?
-
Answer:
You could use a function like str_replace on it before printing the link to the page.
Fero at Stack Overflow Visit the source
Other answers
$array['error'][1] = ..., but from the sound of it, I think you might want to change the value wherever it was set originally. In that case, just search your code for Sorry, unrecognized username or password. or something.
Kenaniah
$somearray['somekey'] = 'newvalue'; $somearray['somekey']['otherkey'] = 'othernewvalue'; ... basic PHP...
Marc B
Related Q & A:
- How to return a value from .ashx file to javascript in a variable?Best solution by forums.asp.net
- how to fetch a value from persistence.xml to build.properties?Best solution by Stack Overflow
- How to upload a file to another server using cURL and PHP?Best solution by Stack Overflow
- How to change input value in formly?Best solution by Stack Overflow
- How to change a dimmer switch back to a regular light switch?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.