I have an array resulted from a function but can't figure out how to set it properly: Array ( [0] => [1] => <br /> [2] => <span class="goToBookChapter" style="font-weight: bold;">Genesis 29:2</span><br /> [3] => <br /> [4] => And he <span class="" id="" style="color:MediumTurquoise; font-weight:bold;">looked</span>, and <span class="" id="" style="color:DarkRed; font-weight:bold;">behold</span> a well in the field, and, lo, there were three <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>s of sheep lying by it; for out of that well they watered the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>s: and a <span class="" id="" style="color:; font-weight:bold;">great</span> stone was upon the well's mouth.<br /> [5] => <br /> [6] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 2:16</span><br /> [7] => <br /> [8] => Now the <span class="" id="" style="color:green; font-weight:bold;">priest</span> of <span class="" id="" style="color:PaleGreen; font-weight:bold;">Midian</span> had seven daughters: and they came and drew water, and filled the troughs to water their <span class="" id="" style="color:Magenta; font-weight:bold;">father</span>'s <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>.<br /> [9] => <br /> [10] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 3:1</span><br /> [11] => <br /> [12] => Now <span class="" id="" style="color:red; font-weight:bold;">Moses</span> kept the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span> of <span class="" id="" style="color:blue; font-weight:bold;">Jethro</span> his <span class="" id="" style="color:Magenta; font-weight:bold;">father</span> in law, the <span class="" id="" style="color:green; font-weight:bold;">priest</span> of <span class="" id="" style="color:PaleGreen; font-weight:bold;">Midian</span>: and he led the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span> to the <span class="" id="" style="color:orange; font-weight:bold;">backside</span> of the <span class="" id="" style="color:purple; font-weight:bold;">desert</span>, and came to the <span class="" id="" style="color:Pink; font-weight:bold;">mountain</span> of God, even to <span class="" id="" style="color:YellowGreen; font-weight:bold;">Horeb</span>.<br /> [13] => <br /> [14] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 3:2</span><br /> [15] => <br /> [16] => And the <span class="" id="" style="color:Sienna; font-weight:bold;">angel</span> of the LORD <span class="" id="" style="color:aqua; font-weight:bold;">appeared</span> unto him in a <span class="" id="" style="color:Gray; font-weight:bold;">flame</span> of fire out of the <span class="" id="" style="color:LightBlue; font-weight:bold;">midst</span> of a bush: and he <span class="" id="" style="color:MediumTurquoise; font-weight:bold;">looked</span>, and, <span class="" id="" style="color:DarkRed; font-weight:bold;">behold</span>, the bush <span class="" id="" style="color:; font-weight:bold;">burned</span> with fire, and the bush was not <span class="" id="" style="color:; font-weight:bold;">consumed</span>.<br /> [17] => <br /> [18] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 3:3</span><br /> [19] => <br /> [20] => And <span class="" id="" style="color:red; font-weight:bold;">Moses</span> said, I will now turn <span class="" id="" style="color:; font-weight:bold;">aside</span>, and see this <span class="" id="" style="color:; font-weight:bold;">great</span> <span class="" id="" style="color:; font-weight:bold;">sight</span>, why the bush is not <span class="" id="" style="color:; font-weight:bold;">burnt</span>.<br /> [21] => <br /> [22] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 17:6</span><br /> [23] => <br /> [24] => <span class="" id="" style="color:DarkRed; font-weight:bold;">Behold</span>, I will stand before thee there upon the rock in <span class="" id="" style="color:YellowGreen; font-weight:bold;">Horeb</span>; and thou shalt smite the rock, and there shall come water out of it, that the people may drink. And <span class="" id="" style="color:red; font-weight:bold;">Moses</span> did so in the <span class="" id="" style="color:; font-weight:bold;">sight</span> of the elders of Israel.<br /> [25] => <br /> [26] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 18:1</span><br /> [27] => <br /> [28] => When <span class="" id="" style="color:blue; font-weight:bold;">Jethro</span>, the <span class="" id="" style="color:green; font-weight:bold;">priest</span> of <span class="" id="" style="color:PaleGreen; font-weight:bold;">Midian</span>, <span class="" id="" style="color:red; font-weight:bold;">Moses</span>' <span class="" id="" style="color:Magenta; font-weight:bold;">father</span> in law, heard of all that God had done for <span class="" id="" style="color:red; font-weight:bold;">Moses</span>, and for Israel his people, and that the LORD had brought Israel out of Egypt;<br /> [29] => <br /> [30] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 18:12</span><br /> [31] => <br /> [32] => And <span class="" id="" style="color:blue; font-weight:bold;">Jethro</span>, <span class="" id="" style="color:red; font-weight:bold;">Moses</span>' <span class="" id="" style="color:Magenta; font-weight:bold;">father</span> in law, took a <span class="" id="" style="color:; font-weight:bold;">burnt</span> offering and sacrifices for God: and Aaron came, and all the elders of Israel, to eat bread with <span class="" id="" style="color:red; font-weight:bold;">Moses</span>' <span class="" id="" style="color:Magenta; font-weight:bold;">father</span> in law before God.<br /> [33] => <br /> [34] => <span class="goToBookChapter" style="font-weight: bold;">Leviticus 10:19</span><br /> [35] => <br /> [36] => And Aaron said unto <span class="" id="" style="color:red; font-weight:bold;">Moses</span>, <span class="" id="" style="color:DarkRed; font-weight:bold;">Behold</span>, this day have they offered their sin offering and their <span class="" id="" style="color:; font-weight:bold;">burnt</span> offering before the LORD; and such things have befallen me: and if I had eaten the sin offering to day, should it have been accepted in the <span class="" id="" style="color:; font-weight:bold;">sight</span> of the LORD?<br /> [37] => <br /> [38] => <span class="goToBookChapter" style="font-weight: bold;">Numbers 16:42</span><br /> [39] => <br /> [40] => And it came to pass, when the congregation was gathered against <span class="" id="" style="color:red; font-weight:bold;">Moses</span> and against Aaron, that they <span class="" id="" style="color:MediumTurquoise; font-weight:bold;">looked</span> toward the tabernacle of the congregation: and, <span class="" id="" style="color:DarkRed; font-weight:bold;">behold</span>, the cloud covered it, and the glory of the LORD <span class="" id="" style="color:aqua; font-weight:bold;">appeared</span>.<br /> [41] => <br /> [42] => <span class="goToBookChapter" style="font-weight: bold;">Numbers 25:6</span><br /> [43] => <br /> [44] => And, <span class="" id="" style="color:DarkRed; font-weight:bold;">behold</span>, one of the children of Israel came and brought unto his brethren a <span class="" id="" style="color:PaleGreen; font-weight:bold;">Midian</span>itish woman in the <span class="" id="" style="color:; font-weight:bold;">sight</span> of <span class="" id="" style="color:red; font-weight:bold;">Moses</span>, and in the <span class="" id="" style="color:; font-weight:bold;">sight</span> of all the congregation of the children of Israel, who were weeping before the door of the tabernacle of the congregation.<br /> [45] => <br /> [46] => <span class="goToBookChapter" style="font-weight: bold;">Ezekiel 1:4</span><br /> [47] => <br /> [48] => And I <span class="" id="" style="color:MediumTurquoise; font-weight:bold;">looked</span>, and, <span class="" id="" style="color:DarkRed; font-weight:bold;">behold</span>, a whirlwind came out of the north, a <span class="" id="" style="color:; font-weight:bold;">great</span> cloud, and a fire infolding itself, and a brightness was about it, and out of the <span class="" id="" style="color:LightBlue; font-weight:bold;">midst</span> thereof as the colour of amber, out of the <span class="" id="" style="color:LightBlue; font-weight:bold;">midst</span> of the fire.<br /> [49] => <br /> [50] => <span class="goToBookChapter" style="font-weight: bold;">Amos 3:9</span><br /> [51] => <br /> [52] => Publish in the palaces at Ashdod, and in the palaces in the land of Egypt, and say, Assemble yourselves upon the <span class="" id="" style="color:Pink; font-weight:bold;">mountain</span>s of Samaria, and <span class="" id="" style="color:DarkRed; font-weight:bold;">behold</span> the <span class="" id="" style="color:; font-weight:bold;">great</span> tumults in the <span class="" id="" style="color:LightBlue; font-weight:bold;">midst</span> thereof, and the oppressed in the <span class="" id="" style="color:LightBlue; font-weight:bold;">midst</span> thereof.<br /> ) Code (markup): The function is: function getQuery($bigWords){ ... $theresult = array(); $theresult[] = ""; //$theresult[] = $query; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ $theresult[] .= "<br />\n"; $theresult[] .= "<span class=\"goToBookChapter\" style=\"font-weight: bold;\">".$row['book_title']." ".$row['chapter'].":".$row['verse']."</span><br />\n"; $strText = $row['text_data']; $COLORS = array('red','Teal','blue','Magenta','green','PaleGreen','orange','purple','Pink','YellowGreen','Sienna','aqua','Gray','LightBlue','MediumTurquoise','DarkRed'); for($m=0; $m < count($bigWords); $m++){ $strText = preg_replace("/(".$bigWords[$m].")/i", "<span class=\"\" id=\"\" style=\"color:".$COLORS[$m]."; font-weight:bold;\">$1</span>", $strText); } $theresult[] .= "<br />\n"; $theresult[] .= $strText."<br />\n"; } return $theresult; echo "<br /><br />".$query."<br />"; } echo "Words searched for:<br />\n"; $bigWords = array_values($bigWords); //to make $k start the $COLORS from 0 $k = 0; for ($j=0; $j < count($bigWords); $j++){ if($bigWords[$j]!=""){ echo "<span style='font-weight: bold; color: ".$COLORS[$k].";'>".$bigWords[$j]."</span>\n"; if($j!=count($bigWords)-1){ echo " + "; }else{ //removes the OR from the last line and replaces with the following //for results of words > 3 echo ".<br />\n"; } $k++; } } print_r(getQuery($bigWords)); PHP: It should be: Array ( [0] =><br /><span class="goToBookChapter" style="font-weight: bold;">Genesis 29:2</span><br /><br />And he <span class="" id="" style="color:MediumTurquoise; font-weight:bold;">looked</span>, and <span class="" id="" style="color:DarkRed; font-weight:bold;">behold</span> a well in the field, and, lo, there were three <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>s of sheep lying by it; for out of that well they watered the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>s: and a <span class="" id="" style="color:; font-weight:bold;">great</span> stone was upon the well's mouth.<br /> [1] => <br /><span class="goToBookChapter" style="font-weight: bold;">Exodus 2:16</span><br /><br />Now the <span class="" id="" style="color:green; font-weight:bold;">priest</span> of <span class="" id="" style="color:PaleGreen; font-weight:bold;">Midian</span> had seven daughters: and they came and drew water, and filled the troughs to water their <span class="" id="" style="color:Magenta; font-weight:bold;">father</span>'s <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>.<br /><br /> [2] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 3:1</span><br /><br />Now <span class="" id="" style="color:red; font-weight:bold;">Moses</span> kept the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span> of <span class="" id="" style="color:blue; font-weight:bold;">Jethro</span> his <span class="" id="" style="color:Magenta; font-weight:bold;">father</span> in law, the <span class="" id="" style="color:green; font-weight:bold;">priest</span> of <span class="" id="" style="color:PaleGreen; font-weight:bold;">Midian</span>: and he led the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span> to the <span class="" id="" style="color:orange; font-weight:bold;">backside</span> of the <span class="" id="" style="color:purple; font-weight:bold;">desert</span>, and came to the <span class="" id="" style="color:Pink; font-weight:bold;">mountain</span> of God, even to <span class="" id="" style="color:YellowGreen; font-weight:bold;">Horeb</span>.<br /> } Code (markup):
Ok ok. By eliminating .= and joining strings together I managed to fix some parts of the array. However there is the first part which causes [0] to show blank. How do I get around $theresult[] = ""; not showing in [0]=>? The reason for avoiding is that I have a pagination code where the first page will show one less because of this: function getQuery($bigWords){ ... $theresult = array(); $theresult[] = ""; //$theresult[] = $query; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ $strText = $row['text_data']; $COLORS = array('red','Teal','blue','Magenta','green','PaleGreen','orange','purple','Pink','YellowGreen','Sienna','aqua','Gray','LightBlue','MediumTurquoise','DarkRed'); for($m=0; $m < count($bigWords); $m++){ $strText = preg_replace("/(".$bigWords[$m].")/i", "<span class=\"\" id=\"\" style=\"color:".$COLORS[$m]."; font-weight:bold;\">$1</span>", $strText); } $theresult[] .= "<br />\n<span class=\"goToBookChapter\" style=\"font-weight: bold;\">".$row['book_title']." ".$row['chapter'].":".$row['verse']."</span><br />\n".$strText; } return $theresult; echo "<br /><br />".$query."<br />"; } PHP:
$theresult = array(); $theresult[] = ""; //<----- take off this line //$theresult[] = $query; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ $strText = $row['text_data']; $COLORS = array('red','Teal','blue','Magenta','green','PaleGreen','orange','purple','Pink','YellowGreen','Sienna','aqua','Gray','LightBlue','MediumTurquoise','DarkRed'); for($m=0; $m < count($bigWords); $m++){ $strText = preg_replace("/(".$bigWords[$m].")/i", "<span class=\"\" id=\"\" style=\"color:".$COLORS[$m]."; font-weight:bold;\">$1</span>", $strText); } $theresult[] .= "<br />\n<span class=\"goToBookChapter\" style=\"font-weight: bold;\">".$row['book_title']." ".$row['chapter'].":".$row['verse']."</span><br />\n".$strText; } return $theresult; echo "<br /><br />".$query."<br />"; } PHP: