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

  • Home
  • SEARCH
  • 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 5951771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:35:07+00:00 2026-05-22T17:35:07+00:00

I want to change the value of an array without loop- Example code: <?php

  • 0

I want to change the value of an array without loop-

Example code:

<?php
    //current array
    $ids = array('1113_1', '1156_6', '1342_16', '1132_3', '1165_2');

    //result should be looks like this
    $ids = array('1113', '1156', '1342', '1132', '1165');
?>

is it possible to do it without any loop?

  • 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-05-22T17:35:07+00:00Added an answer on May 22, 2026 at 5:35 pm

    Try this using array_map():

    <?php
    function remove_end($n)
    {
        list($front) = explode("_", $n);
        return $front;
    }
    
    $a = array('1113_1', '1156_6', '1342_16', '1132_3', '1165_2');
    $a = array_map("remove_end", $a);
    print_r($a);
    ?>
    

    Demo: http://codepad.org/iGJ3cJW2

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

Sidebar

Related Questions

Say I want to change a value for all objects in an array. I
Hey all, I want to change a value in a table (in a mysql
I want to change the variable value which is a member of a structure
I want to change master page some label value from child page.
I want to use Thread.VolatileWrite() (or an equivalent function) to change the value of
I want to change the SelectItem[] array in the second SelectOneMenu , if the
I need to change the value of a line within an array to a
I have an array in ruby and i want to change the values of
I want to change the number in the first array in a multidimensional array.
I want to cange the lables in my form according to particular value in

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.