Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Kindly help me with my code:
$a[1]='cloropil';
$a[2]='rodopayta';
$r=2;
$c=1;
$f= while($c<=$r){ echo $a[$c];;
$e = $c++ };
while($c<=$r){
echo $f;
$r++;
}
while($c<=$r){
echo $e;
$r++;
}
I want its output to be like this:
$a[1]='cloropil';
$a[2]='rodopayta';
$r=2;
$c=1;
while($c<=$r){
echo $a[$c];
while($c<=$r){
echo $a[$c];
$c++;
}
$c++;
}
How ever the out put is blank.
it should even display at least "cloropil".
Is this even possible?
I want to display something like this:
cloropilcloropil
cloropilrodopyta
rodopytacloropil
rodopytarodopyta
thank you very much in advance.
I think this may be what you are looking for?:
<?php
$a[]='cloropil';
$a[]='rodopayta';
// You first iterate over each
for($i = 0; $i < count($a); $i++)
{
// As you iterate through the first round, you iterate
// again to match pairs but include the first iteration
// value with this second
foreach($a as $val)
echo $a[$i].'=>'.$val.'<br />';
}
?>
Gives you:
cloropil=>cloropil
cloropil=>rodopayta
rodopayta=>cloropil
rodopayta=>rodopayta
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
how do i loop this kind of array?
$arr = array (
"aa"=>array("apple","orange"),
"bb"=>array("373","22"),
"cc"=>array("t0","h0"),
"dd"=>array("1","0")
);
I want to loop through the column of each item.
e.g.: i want to display ('apple','373','t0','1') at the first loop and ('orange','22','h0','0') at the last loop. thanks
We are assuming that all the arrays inside the main array are the same size in this example.
$arr = array (
"aa"=>array("apple","orange"),
"bb"=>array("373","22"),
"cc"=>array("t0","h0"),
"dd"=>array("1","0")
);
for($i = 0; $i<sizeof($arr["aa"]); $i++)
{
foreach($arr as $key=>$item)
{
echo($item[$i]);
}
echo ' - ';
}
Output: (obviously you can do any necessary formatting you need such as new lines or commas)
apple373t01 - orange22h00 -
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
foreach($reciveValue as $value){
echo $value.",";// Result: based on user input like:10,11,12,13,14
}
echo $value; // Result: 14
the result inside loop is: 10,11,12,13,14
and outside loop is : 14
I want to use all value outside of loop
Use below code to get your array values comma seperated
implode(",", $reciveValue)
Try this :
$value = '';
foreach($reciveValue as $val){
$value .= $val.",";// Result: based on user input like:10,11,12,13,14
}
echo rtrim($value, ',');
#Support Techcherry if you want to use all values of an array outside
the loop then you can use implode() function, below is an example
understand
<?php
$reciveValue = array(10,11,12,13,14); // suppose this is your array
foreach($reciveValue as $value){
echo $value.",";// Result: based on user input like:10,11,12,13,14
}
echo "<br>";
echo implode(',', $reciveValue); // here implode() function convert the array value in the string form
?>
try it, it will help you
thanks to everyone for posting answer
every answer is very helpful for me
but finally i got my solution
$result="";
foreach($reciveValue as $value)
{
$result=$value.",".$result;
}
echo $result;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Sir i have some problem about array. this is my code
$isi = array('1','6','7','9','4');
$cekarray = array('1','6','2');
if(!empty($cekarray[$isi]))
{
echo "b = ".1."<br>";
}
else
{
echo "b = ".0."<br>";
}
i hope output it should be look like
b = 1
b = 1
b = 0
thanks before sir
I think you are trying to find out which items in the $cekarray exist in the $isi array.
Here is one simple method of doing that
<?php
$isi = array('1','6','7','9','4');
$cekarray = array('1','6','2');
foreach ( $cekarray as $val) {
if ( in_array($val, $isi) ) {
echo "b = 1<br>";
} else {
echo "b = 0<br>";
}
}
If you want to check whether the values from $cekarray are present in $isi, this should give the desired output:
$isi = array('1','6','7','9','4');
$cekarray = array('1','6','2');
foreach ($cekarray as &$cekarrayValue) {
foreach ($isi as &$isiValue) {
if($cekarrayValue==$isiValue)
echo "b = 1<br />";
else
echo "b = 0<br />";
}
}
Well, only in this case. Depending on what you want, functionality must be added but it's a start. You can also take a look at in_array() function.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
<?php
$val=array(4,10,15);
$val2=array('ravi,suresh,kumar');
foreach ($val2 as $title) {
foreach ($val as $title1) {
echo $title;
echo $title1;
}
}
?>
o/p:
ravi,suresh,kumar4ravi,suresh,kumar10ravi,suresh,kumar15
but i requeied
ravi 4
suresh10
kumar15
Use one loop.
for($i = 0; $i < count($val); $i++) {
print $val[$i] . " " . $val2[$i];
}
The issue with your nested for loops is that it iterates over the first element of val1, then all the elements of val 2. Then the 2nd element of val1, and all the elements of val2 and so on.
since you want to go through both at the same time, use a standard for loop.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Sorry for my english..
in mysql has row name iurl.. There is data: 1365269423.jpg,1365270586.jpg,1365270666.jpg,1365270683.jpg
i get its as:
<?php $s=mysql_query("select iurl from points where id='".$_GET['id']."' ");
if($s){
$array = array();
while($t=mysql_fetch_array($s)) {
$array[] = $t['iurl'];
}
print_r($array);
?>
it gives me result: Array ( [0] => 1365269423.jpg,1365270586.jpg,1365270666.jpg,1365270683.jpg )
And i`m need get it and print like a link
how can i do it?
Thanks..
You can use explode(); to split the string into an array and then loop over to print each item:
$images = explode(",", $t["iurl"]);
foreach ($images as $image) {
echo "{$image}";
}
I think you are asking to have result or in your case a .jpg file be the href of your link? If so do this:
......
The result you get from your database as you already figured out is an Array
The only thing you need to do is loop trough the array.
ps: consider using mysqli more info at php.net http://www.php.net/manual/en/book.mysqli.php
<?php
$s=mysql_query("select iurl from points where id='".$_GET['id']."' ");
while ($row = mysql_fetch_object($s)) {
echo '<img="http://yourhost.com/images/'.$row->image.' alt=""/>';
}
?>