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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:43:10+00:00 2026-06-18T02:43:10+00:00

How can I pass an array to a function? Let’s say I have this

  • 0

How can I pass an array to a function?

Let’s say I have this multi-dimensional array:

$TheArray = (
array("Value 1 0","Value 1 1","Value 1 2"),
array("Value 2 0","Value 2 1","Value 2 2"),
array("Value 3 0","Value 3 1","Value 3 2")
);

Instead of doing this…

for ($i=0; $i<=(count($TheArray)-1); $i++)
{
echo $TheArray[$i][0] . " " . $TheArray[$i][1] . " " . $TheArray[$i][2] . "<br />";
}

I want to do this…

function DoStuffWithTheArray($SubArr)
{
echo $SubArr[0] . " " . $SubArr[1] . " " . $SubArr[2] . "<br />";
}

for ($i=0; $i<=(count($TheArray)-1); $i++)
{
DoStuffWithTheArray($TheArray[$i]);
}

Hopefully, you can tell what I am trying to do, but I do not know how to get it to work. When I do try it the way I want, all the values are empty

  • 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-18T02:43:12+00:00Added an answer on June 18, 2026 at 2:43 am

    I think, you need to learn first how create an array;

    // instead of this
    $TheArray = (...
    // you can create an array so
    $TheArray = array(...
    

    Second, change this style please and see: http://php.net/manual/en/control-structures.foreach.php

    for ($i = 0; $i < count($TheArray); $i++)
    

    And answer;

    $array = array(
        array("Value 1 0", "Value 1 1", "Value 1 2"),
        array("Value 2 0", "Value 2 1", "Value 2 2"),
        array("Value 3 0", "Value 3 1", "Value 3 2")
    );
    
    function fn($a) {
        print "$a[0], $a[1], $a[1]\n";
    }
    
    foreach ($array as $a) fn($a);
    
    Value 1 0, Value 1 1, Value 1 1
    Value 2 0, Value 2 1, Value 2 1
    Value 3 0, Value 3 1, Value 3 1
    
    • 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 contains around 50-200 hyperlinks. How can I pass this
Let's say I have an array like this $update = array( 'field1' => 'one',
Let's say I have a function called MyFunction(int myArray[][]) that does some array manipulations.
Can i pass the entire POST array into a function and handle it within
Let's Say I Have This Class: package{ import flash.display.Sprite; public class Main extends Sprite{
let's say i have a string like this: $string = 'Lorem Ipsum available, <a
I have a function that I pass an array into and an int into
Is there any way can C# pass an array in function like C++? In
How can I pass array value from one page to another in php and
How can I pass a array name into a function and read values dynamically?

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.