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 9241505
In Process

The Archive Base Latest Questions

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

i try with success when combine 2 array into one foreach loop .. <?php

  • 0

i try with success when combine 2 array into one foreach loop ..

<?php
//var
$phone_prefix_array = $_POST['phone_prefix']; //prefix eg. 60 (for country code)
$phone_num_array    = $_POST['phone'];
$c_name_array       = $_POST['customer_name'];

foreach (array_combine($phone_prefix_array, $phone_num_array) as $phone_prefix => $phone_num) { //combine prefix array and phone number array
    $phone_var = $phone_prefix . $phone_num;
    $phone     = '6' . $phone_var;

    if ($phone_prefix == true && $phone_num == true) { //filter if no prefix number dont show

        echo $phone;
        //customer_name_here

    } else {
  }

}
?>

The result should be like this :

60125487541 Jake
60355485541 Kane
60315488745 Ray
63222522125 Josh

but now im not sure how to combine another array $c_name_array into foreach lopp

PHP version : 5.2.17

  • 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:23:00+00:00Added an answer on June 18, 2026 at 8:23 am

    array_combine is a terrible workaround for your case and will not work if any value in the first array is not a valid key (i.e. not int or string)

    PHP 5.3+ has a MultipleIterator for this:

    $iterator = new MultipleIterator();
    $iterator->attachIterator(new ArrayIterator($phone_prefix_array));
    $iterator->attachIterator(new ArrayIterator($phone_num_array));
    foreach ($iterator as $current) {
        $phone_prefix = $current[0];
        $phone_num = $current[1];
        // ...
    }
    

    Since PHP 5.4 you can write the loop more concise:

    foreach ($iterator as list($phone_prefix, $phone_num)) {
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code: try { $result = Model_User::update_user($_POST); // message: save success Message::add('success',
How do I properly declare a or statement i try this without success: <c:forEach
I am parsing a JSON string: Response: {success:false,displaymessage:UserName or Email already exist. Please try
I try to use ComboxBoxTableCell without success. The content of the cell display the
I try to install n'th time the msys+mingw - however with little success. I
I've seen this pattern a few times now: bool success = false; try {
Error: ReferenceError: setDynaTreeCustom is not defined add.js Code: ...... success: function(treeData){ try{ showPopup(Add Fields|,'multi_list','event',0,0,1);
I do something wrong, but I don't know what. I try to combine django-registration
My first question here. The question is similar to this one: PHP: Retrying a
During trying to combine submit and upload in one form, I have a problem

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.