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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:24:22+00:00 2026-05-15T12:24:22+00:00

I have an array from a $_GET say Array ( [0] => 0 [1]

  • 0

I have an array from a $_GET say

Array
        (
            [0] => 0
            [1] => 1
            [2] => 2
            [3] => 3
            [4] => 4
        )

for which i am using this while loop to create a string:

while (list($key, $value) = each($_GET)) {

          $get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&';

      }

Now if i get an array from $_GET say like:

Array
(
    [0] => pid
    [1] => gid
    [2] => Array
        (
            [0] => 0
            [1] => 1
            [2] => 2
            [3] => 3
            [4] => 4
        )

)

then in this case what could be the possible changes be done to while loop so that I can avoid the result like this http://www.example.com/shopping_cart.php?0=pid&1=gid&2=Array in url when i use this to redirect it.
I want the url to display the values properly..not like “2=Array“.. how can i do this?

EDIT

Thanks Folks for the help, but I cannot introduce new function neither I can replace the while loop with for loop, I would be very thankfull if you can help me in re-editing the given WHILE Loop…

EDIT 2

I am using header(location:$get_url) for redirecting to created url, is this the problem of display of “2=Array” in url?

EDIT 3

functions used to build query, NOTE: THESE FUNCTIONS ARE INBUILT FUNCTION OF osCommerce

I still changed one of it by introducing the foreach loop into it see below the use and function definition:

function tep_redirect($url) {
    if ( (strstr($url, "\n") != false) || (strstr($url, "\r") != false) ) { 
      tep_redirect(tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false));
    }

    if ( (ENABLE_SSL == true) && (getenv('HTTPS') == 'on') ) { // We are loading an SSL page
      if (substr($url, 0, strlen(HTTP_SERVER . DIR_WS_HTTP_CATALOG)) == HTTP_SERVER . DIR_WS_HTTP_CATALOG) { // NONSSL url
        $url = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG . substr($url, strlen(HTTP_SERVER . DIR_WS_HTTP_CATALOG)); // Change it to SSL
      }
    }

    $url =  str_replace("&", "&", $url);

    header('Location: ' . $url);

    tep_exit();
  }

=========================

   function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
        global $request_type, $session_started, $SID, $spider_flag;

        if (!tep_not_null($page)) {
          die('</td></tr></table></td></tr></table><br><br><font color="#ff0000">' . TEP_HREF_LINK_ERROR1);
        }

        if ($connection == 'NONSSL') {
          $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
        } elseif ($connection == 'SSL') {
          if (ENABLE_SSL == true) {
            $link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG;
          } else {
            $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
          }
        } else {
          die('</td></tr></table></td></tr></table><br><br><font color="#ff0000">' . TEP_HREF_LINK_ERROR2);
        }

        if (tep_not_null($parameters)) {
          while ( (substr($parameters, -5) == '&amp;') ) $parameters = substr($parameters, 0, strlen($parameters)-5);
          $link .= $page . '?' . tep_output_string($parameters);
          $separator = '&amp;';
        } else {
          $link .= $page;
          $separator = '?';
        }


        // if session is not started or requested not to add session, skip it
        if ( ($add_session_id == true) && ($session_started == true) ){

          // if cookies are not set and not forced, then add the session info incase the set cookie fails 
          if ( ! isset($_COOKIE[tep_session_name()]) && (SESSION_FORCE_COOKIE_USE == 'False') ) {
            $_sid = tep_session_name() . '=' . tep_session_id();

          // if we are chaning modes and cookie domains differ, we need to add the session info
          } elseif ( HTTP_COOKIE_DOMAIN . HTTP_COOKIE_PATH != HTTPS_COOKIE_DOMAIN . HTTPS_COOKIE_PATH
                     &&
                     (
                       ( $request_type == 'NONSSL' && $connection == 'SSL' && ENABLE_SSL == true )
                       ||
                       ( $request_type == 'SSL' && $connection == 'NONSSL' )
                     )
                   ) {
            $_sid = tep_session_name() . '=' . tep_session_id();
          }

        }

        if (isset($_sid) && !$spider_flag) {
          $link .= $separator . tep_output_string($_sid);
        }

        return $link;
      }

===========================

function tep_get_all_get_paramtrs($exclude_array = '') {
    global $HTTP_GET_VARS;

    if (!is_array($exclude_array)) $exclude_array = array();

    $get_url = '';
    if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) 
    {
      reset($HTTP_GET_VARS);
      foreach($HTTP_GET_VARS as $key => $a)
      {
        if(is_array($a))
        {
            foreach($a as $k => $v)
            {
                $get_url[] = $key . '[]' . '=' . rawurlencode(stripslashes($v));
            }
        }
        else
        {
            $get_url[] = $key . '=' . rawurlencode(stripslashes($a));
        }
      }

   /*   while (list($key, $value) = each($HTTP_GET_VARS)) 
      {
      if(!is_array($value))
      {
        if ( (strlen($value) > 0) && ($key != tep_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) 
        {
          $get_url .= $key . '=' . rawurlencode(stripslashes($value));
        }
      }
      else
      {

      if ( (strlen($value) > 0) && ($key != tep_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) 
        {
          $get_url .= preg_replace('/#\d/','[]',http_build_query($value,$key.'#'));
        }
     /*     while(list($key1, $value1) = each($value))
        {
            if ( (strlen($value1) > 0) && ($key1 != tep_session_name()) && ($key1 != 'error') && (!in_array($key1, $exclude_array)) && ($key1 != 'x') && ($key1 != 'y') ) 
            {
              $get_url .= $key1 . '=' . rawurlencode(stripslashes($value1));
            }
        }*/
     /* }
      }*/
      $get_url .=  '&amp;';
    }

    return $get_url;
  }

========================

tep_redirect(tep_href_link($goto, tep_get_all_get_paramtrs($parameters)));

here $parameters is an array with two values which doesnt have any resemblence with url display logic

  • 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-15T12:24:23+00:00Added an answer on May 15, 2026 at 12:24 pm

    If you want to create an url from a multi-dimensional array, you should use a recursion, or just the built-in php function, which results the same as the function I created http-build-query() (just as Maurice Kherlakian said). It’s the easiest way for doing this.

    A recursive function example:

    function URLfromArray($array,$url = "")
    {
    
        foreach($array as $key => $val)
        {
            if(is_array($val))
            {
                $url = URLfromArray($val,$url);
            }
            else
            {
                $url .= $key."=".$val."&";
            }
        }
    
        return $url;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 429k
  • Answers 429k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The Groovy compiler will of course find syntax errors, but… May 15, 2026 at 1:39 pm
  • Editorial Team
    Editorial Team added an answer MySQL triggers have implicit transaction support, so the trigger cannot… May 15, 2026 at 1:39 pm
  • Editorial Team
    Editorial Team added an answer If you're writing the file, you should specify open(filename, "wb").… May 15, 2026 at 1:39 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.