/    Sign up×
Community /Pin to ProfileBookmark

multiple instances of value output from single instance of value in array

So this is array i’m working with
Array ( [0] => Traditional Favourites [1] => Starters [2] => Mains )
looping through this using the following:

[code]
$val = $resultsCatTitle[‘CategoryTitle’];
$resultArrMainCatgTitle[] = $val;
reset($resultArrMainCatgTitle);
while (list($key, $val) = each($resultArrMainCatgTitle)) {

if($val === “Traditional Favourites”) {

echo $val;
}
[/code]

there is only one instance of the value “Traditional Favourites” in the array but using echo $val puts out the following:

Traditional FavouritesTraditional FavouritesTraditional Favourites

I’ve also tried a for loop that too provides the same result. Is there a reason behind is? and how would I go about correcting this? It should only come back with 1 instance shouldn’t it?

__(replaced single back-ticks with `[code]…[/code]` tags ~ MOD)__

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 18.2019 — In interactive mode, and assuming I'm correctly interpreting the expected content of $resultArrMainCatgTitle, it seems to work fine:
<i>
</i>php &gt; $resultArrMainCatgTitle = ['Traditional Favourites', 'Starters', 'Mains'];
php &gt; while (list($key, $val) = each($resultArrMainCatgTitle)) {
php { if($val === "Traditional Favourites") {
php { echo "$valn";
php { }
php { }
Traditional Favourites
php &gt;

So, I'd start by dumping the contents of $resultArrMainCatgTitle right before you would use it, and see if it's actually what you think it is, e.g.:
<i>
</i>die("&lt;pre&gt;".var_export($resultArrMainCatgTitle, 1)."&lt;/pre&gt;");
×

Success!

Help @nsath spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.10,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...