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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:00:13+00:00 2026-06-03T05:00:13+00:00

I need to print contents of multiple arrays in my code. Eg function performOp($n,

  • 0

I need to print contents of multiple arrays in my code. Eg

   function performOp($n, $inputArr, $workArr)
    {
        printf("Entered function, value of n is %d", $n);
    print_r($inputArr);
    print_r($workArr);
        $width =0;
    }

Now, Instead of writing print_r twice, is there any way I can write a single statement and print both the arrays ?
Also, If I want to print “Input array value is ” before displaying the Array{}, is there a way to do so using printf or any other function?

I tried writing

    printf("Value of inputArray is %s ", print_r($inputArr)

, but this would not work.

Any help is really appreciated.

Thanks

  • 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-03T05:00:15+00:00Added an answer on June 3, 2026 at 5:00 am

    Dumping the Variables

    You can pass multiple arrays into var_dump().

    var_dump( $array, $array2, $array3 );
    

    For instance, the following:

    $array = array("Foo", "bar");
    $array2 = array("Fizz", "Buzz");
    
    var_dump( $array, $array2 );
    

    Outputs this:

    array(2) { [0]=> string(3) "Foo" [1]=> string(3) "bar" }
    array(2) { [0]=> string(4) "Fizz" [1]=> string(4) "Buzz" }
    

    Note how it keeps both arrays distinct in the output as well.

    Function with n-arguments

    You could also use a function, calling upon func_get_args() for the arrays passed in:

    function logArrays() {
      $arrays = func_get_args();
      for ( $i = 0; $i < func_num_args(); $i++ )
        printf( "Array #%d is %s", $i, print_r($arrays[$i], true) );
    }
    
    logArrays( $array, $array2 );
    

    Which, in this case, would output the following:

    Array #0 is Array ( [0] => Foo  [1] => bar  )
    Array #1 is Array ( [0] => Fizz [1] => Buzz )
    

    Using json_encode() instead of print_r would output a slightly more readable format:

    Array #0 is ["Foo","bar"]
    Array #1 is ["Fizz","Buzz"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to print the ASCII value of the given character in awk only.
I need to print the contents of my groovy console onto a swing Builder's
Need help with PHP Mysql code to insert multiple select data into database. With
We need to print thousands of invoices that are in this format - http://example.com/orders/n
I need to print the below string which is in Arabic on TextView in
I need to print out data into a pre-printed A6 form (1/4 the size
I need to print the date in the format of mm/dd/yyyy. if the date
I need to print records in a grid view, and need to preview it
i need to print out numbers 1-100 in a random order. the print statement
I need to print a receipt from my web based apps using dot matrix

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.