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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:37:23+00:00 2026-05-31T23:37:23+00:00

I have an array which is storing server addresses like so $servers = array(

  • 0

I have an array which is storing server addresses like so

$servers = array(
  'UK'=>array(
    'voi' =>  '54.53.23.32',
    'gps' =>  '55.65.34.34',
    'sos' =>  '54.54.34.23'
  ),
  'USA'=>array(
    'voi' =>  '12.23.45.67',
    'gps' =>  '65.443.23.45',
    'sos' =>  '12.23.456.4'
  )
);

I have a form which is listing the server locations

<select name="server" id="server">
<?php foreach($servers as $key => $arr){
echo "<option>" .$key. "</option>"; }
?>
</select>

Once the form is submitted i need to set a session variable with the correct countrys IP’s

$_SESSION['voi']=$submitted_countrys_voi_ip;
$_SESSION['gps']=$submitted_countrys_gps_ip;

etc..

How can i choose the correct key based on the form post and get the values from the sub array into a session variable?

  • 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-31T23:37:24+00:00Added an answer on May 31, 2026 at 11:37 pm

    First of all, you select does not have a value. So fixed that first

    <select name="server" id="server">
    
        <?php foreach($servers as $key => $arr){
        echo "<option value='$key'>" .$key. "</option>"; }
        ?>
    
    </select>
    

    Then, after the form is submitted. Assuming that form is submitted using POST method

    $server = ..; //Being your array of ips
    $sub_server = $_POST['server']; //get the submitted server
    $_SESSION['voi'] = $server[$sub_server]['voi'];
    $_SESSION['gps'] = $server[$sub_server]['gps'];
    // and so on
    

    Improvement

    In case you have lots of IP’s for a nation, then you might want to create an array of the types first.

    $server = ..; 
    $types = array('voi','gps', 'sos'); //TYPES in a single array
    $sub_server = $_POST['server']; 
    foreach($types as $type) {
        $_SESSION[$type] = $server[$sub_server][$type];
    }
    

    This is automatically assign every types at once.

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

Sidebar

Related Questions

i have an array which could look like this: $config[$name][$array]['key'] = 'value'; // here
I have a js code in which an array works well when its like
I have a multi-dimensional array of databases, which was generated from my server: //
I have a form which I would like to store the values of in
I have a string say string s =C:\\Data , I have an array which
I have an array of strings in python which each string in the array
I have a .NET string which is Base64 encoded representation of an array of
I have an array which is a list of domains, I want to print
I have an array which contains another array Would I notate it this way?
I have an array which has the contents as the result of an sql

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.