Jump to content

array quesition


applelover

Recommended Posts

Try

 

<?php

$text = "The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog";
$text = explode(" ", $text);

//array to hold the sections of words in
$words = array();

//var to hold the sets in
$set = "";

$count = 1;

foreach ($text as $word){
   
   $set .= $word . ' ';
   
   if ($count == 100){
      $words[] = $set;
      $set = "";
      $count = 0;
   }
   
   $count++;
}

echo '<pre>',print_r($words),'</pre>';

?>

Link to comment
https://forums.phpfreaks.com/topic/107233-array-quesition/#findComment-549789
Share on other sites

or

<?php
$a = "The quick brown fox jumps over the lazy dog. ";
$a = str_repeat($a, 50);
$a = explode(' ', $a);
$a = array_chunk($a, 100);
foreach ($a as $c) $out[] = implode(' ', $c);
print_r($out);
?>

 

That pretty much put my code to shame...much more efficient.

Link to comment
https://forums.phpfreaks.com/topic/107233-array-quesition/#findComment-549798
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.