Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 01-23-2022, 01:50 PM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,141
Array question in php output

So I have a basic script written to output word variables (code below) but Its displaying the following when it runs:

[0] => oneone
[1] => onetwo
[2] => twotwo
[3] => twoone

Any pointers on how I can remove the [X] = > part from the output so the list is clean?

Here is the code I'm working with:

Quote:
<?php

function permutations($arr,$n)
{
$res = array();

foreach ($arr as $w)
{
if ($n==1) $res[] = $w;
else
{
$perms = permutations($arr,$n-1);

foreach ($perms as $p)
{
$res[] = $w."".$p;
}
}
}

return $res;
}


// Your array
$words = file('numbers.txt',FILE_IGNORE_NEW_LINES);


// Get permutation by groups of 2 elements
$pe = permutations($words,2);

// Print it out
echo "<pre>";
preg_replace('([0-9]+)', '$1', $array );
$v = print_r($pe,true);
echo $v;
echo "<pre>";
?>
I was thinking it had something to do with this part:

Quote:
$res[] = $w
But I changed it a few times and it didnt like the code.

Any help/pointers would be appreciated, It seems like a simple fix?
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-23-2022, 02:51 PM   #2
ZTT
Confirmed User
 
ZTT's Avatar
 
Industry Role:
Join Date: Apr 2019
Posts: 657
Looks like you're just echoing "print_r", printing the whole array.

Try something like this to loop through the values (there are other ways to loop, if you prefer):

foreach ($pe as $pelist) {echo "$pelist\n";}
__________________
__________________
ZTT is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-23-2022, 03:43 PM   #3
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,141
Quote:
Originally Posted by ZTT View Post
Looks like you're just echoing "print_r", printing the whole array.

Try something like this to loop through the values (there are other ways to loop, if you prefer):

foreach ($pe as $pelist) {echo "$pelist\n";}
Thanks for the suggestion.

I've tried the code you just suggested but it appears to cut the amount of results significantly (from 100+ down to roughly 20 from the array).

Any thoughts on why that might be happening?
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-23-2022, 04:06 PM   #4
ZTT
Confirmed User
 
ZTT's Avatar
 
Industry Role:
Join Date: Apr 2019
Posts: 657
Hard to say since I can't see the exact code and/or what you're doing, but do the print_r as you have it there, or var_dump, and underneath do the loop, and compare the array values to see if they match or some are missing. If that's not what you did already.

I mean if "pe" contains 100 items, 100 should be printed and 100 should be listed by the loop. For example:

Code:
$pe=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100];

print_r($pe); 

foreach ($pe as $pelist) {echo "$pelist ";}
__________________
__________________

Last edited by ZTT; 01-23-2022 at 04:14 PM.. Reason: code formatting
ZTT is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
code, output, thinking, list, clean, help/pointers, appreciated, simple, $res[], changed, fix, times, helpme, pointers, variables, word, displaying, written, script, question, php, basic, runs, array, twoone



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.