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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:11:18+00:00 2026-06-11T18:11:18+00:00

I’m trying to make a list from a bidimensional array, showing both keys and

  • 0

I’m trying to make a list from a bidimensional array, showing both keys and the value in that position in each line. This is the code I’ve made.

$array1=array(...);
$array2=array(...);
(...)
$array25=array(...); //this part works fine so I'm not posting all of it
$bigarray['array1']=$array1;
$bigarray['array2']=$array2;
//and so on. This also works as it should
$matrix=file(mylist.txt); //this file holds all the keys I want to print, with the format key1##key2

function printthelist($array)
{
    global $bigarray,$key1,key2;
    $line=explode("##",$array);
    $key1=$line[0];
    $key2=$line[1];
    echo 'Column:'.$key1.rtrim($key2).$bigarray[$key1][rtrim($key2)].'<br/>';
}

array_walk($matrix,'printthelist');

Both keys print correctly, but when I try to get the array values printed they just don’t show. I’ve tried fixed values instead of variables as keys and it worked, both inside and outside the function. I must be missing something, I just don’t know what.

Since you asked, here’s a sample of one of the arrays:

$ib=array();
$ib[4]='Diagnostics in hospitals';
$ib[5]='False positives';
$ib[6]='Risk Factors';
$ib[7]='Protect yourself from infections';

And this is the content of the file which holds the keys to print:

other##16
invitro##9
ib##19
invitro##8
other##13
knowmore##14
psico##10
med##23
patients##19
patients##18
other##12
  • 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-11T18:11:19+00:00Added an answer on June 11, 2026 at 6:11 pm

    I’ve found the problem. The file() function makes an array from a text file, placing every line in a position of said array. However, it does not strip the EOL charachter. This means that every value imported this way has a ‘/n’ at the end. You need to remove it with rtrim() before using this data inside any function. NOTE: this also means that the file() function always returns an array of strings, even though the file only contains numbers. The documentation for this function shows that it is possible to omit the EOL charachter by adding an extra parameter after the name of the file, however, it doesn’t work in all versions of PHP.

    I’ve edited the code, now it works fine.

    Thank you all for your help.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.