Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9241233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:20:05+00:00 2026-06-18T08:20:05+00:00

Why not give the correct exit code? My full code: <?php $numA_m = "2";

  • 0

Why not give the correct exit code?

My full code:

<?php

$numA_m = "2";
$res = '["110","2","1"]';
$numA_s = json_decode($res);
if ($numA_m == 1) {
    $A_num_s = array("1", "2", "3", "4","110");
    $A_nam_s = array("egh", "guide", "irl", "tic", "all");
}
if ($numA_m == 2) {
    $A_num_s = array("1", "2","110");
    $A_nam_s = array("sub", "forg","all");
}
$Rsp = str_replace($A_num_s, $A_nam_s, $numA_s);
$Rsp_In = str_replace($A_nam_s, $A_num_s, $Rsp);
echo '<pre>';
print_r($Rsp);

echo '<p>';

echo '<pre>';
print_r($Rsp_In);
?>

The output should be:

Array (
[0] => all
[1] => forg
[2] => sub
)

Array (
[0] => 110
[1] => 2
[2] => 1
)

But it is like this:

Array
(
[0] => subsub0
[1] => forg
[2] => sub
)
Array
(
[0] => 110
[1] => 2
[2] => 1
)

What do i do?

DEMO: http://phpfiddle.org/main/code/srj-k3d

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:20:06+00:00Added an answer on June 18, 2026 at 8:20 am

    This outputs the desired result

    $numA_m = "2";
    $res = '["110","2","1"]';
    $numA_s = json_decode($res);
    if ($numA_m == 1) {
        $A_num_s = array("1", "2", "3", "4", "110");
        $A_nam_s = array("egh", "guide", "irl", "tic", "all");
    }
    if ($numA_m == 2) {
        $A_num_s = array("110", "2", "1"); // changed order
        $A_nam_s = array("all", "forg", "sub");
    }
    $count = 1;
    $Rsp = str_replace($A_num_s, $A_nam_s, $numA_s, $count);
    $Rsp_In = str_replace($A_nam_s, $A_num_s, $Rsp, $count);
    echo '<pre>';
    print_r($Rsp);
    
    echo '<p>';
    
    echo '<pre>';
    print_r($Rsp_In);
    

    Explanation:

    str_replace searches for the strings in the order you send them. So, if in your case you are searching for 1 and then 110, it will replace all occurrences of 1 before reaching the 110.

    If you replace the 110 first, it will be replaced as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code does not give a warning with g++ 4.1.1 and -Wall .
The following servlet filter is getting called, but not able to give the correct
Why does the following not give an error? for (int i=0; i<10; ++i) //
I want to disable or also I have does not give permission entering the
I have the following stack trace from valgrind. But it does not give me
I was pretty surprised when i saw http://www.vorbis.com/music/Hydrate-Kenny_Beltrey.ogg link not give me a download
Not sure how to ask this, but i'll give it a try: I have
How to give alert if the app is already installed in android,if not how
Im not even sure how to ask this question, but i'll give it a
Why does the MySQL query below give error 1066 (Not unique table/alias: 'customer') ?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.