Reputation: 7240
I have a string as shown bellow:
SIM types:Azadi|Validity:2 Nights|Expirable:yes
I have the following code to seperate them by |
and then show them line by line
$other = "SIM types:Azadi|Validity:2 Nights|Expirable:yes";
$others['items'][] = explode("|",$other);
for($i = 0; $i < count($others['items']); $i++){
echo $others['items'][$i];
}
but the for
loop is iterated only once and prints only the first value. This is what i am getting now:
SIM types:Azadi
Upvotes: 0
Views: 92
Reputation: 28763
Try like this
$others['items'] = explode("|",$other);
$my_count = count($others['items']);
for($i = 0; $i < $my_count; $i++){
echo $others['items'][$i];
}
Upvotes: 3
Reputation: 4282
Try this:
<?php
$other = "SIM types:Azadi|Validity:2 Nights|Expirable:yes";
$others = explode("|",$other);
$total = count($others);
for($i = 0; $i < $total; $i++){
echo $others[$i];
}
?>
Upvotes: 0
Reputation: 32740
Change
$others['items'][] = explode("|",$other);
to
$others['items'] = explode("|",$other);
remove []
Explode will return a array. ref: http://php.net/manual/en/function.explode.php
$other = "SIM types:Azadi|Validity:2 Nights|Expirable:yes";
$others['items'] = explode("|",$other);
for($i = 0; $i < count($others['items']); $i++){
echo $others['items'][$i];
}
Upvotes: 1