foreach

PHP avoid double foreach when looping into an array of an array [closed]

。_饼干妹妹 提交于 2020-01-05 05:34:06
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I have this kind of array: Array ( [data] => Array ( [0] => Array ( [name] => Lskdjlkdsfj [start_time] => 2013-06-12 [timezone] =>

Run a php foreach loop on multi-dimensional array

允我心安 提交于 2020-01-05 05:25:52
问题 I need to run a foreach script on a multi-dimensional array. The original JSON is formatted like: { "_links":{ }, "chatter_count":15, "chatters":{ "moderators":[ "moderator1", "moderator2", "moderator3" ], "staff":[ "staff1", "staff2", "staff3" ], "admins":[ "admin1", "admin2", "admin3" ], "global_mods":[ "global_mod1", "global_mod2", "global_mod3" ], "viewers":[ "viewer1", "viewer2", "viewer3" ] } } Having run json_decode to get a PHP data structure, I'm now lost on how to run a foreach loop

Nested foreach if else not working

安稳与你 提交于 2020-01-05 03:24:55
问题 I have a nested foreach loop going through 2 arrays with a conditional if - else . When if returns a value the else statement is also still running, why is that? //$global_plugins is an array //$xml_plugins is a string foreach($global_plugins as $key => $global_plugins){ foreach ((array) $xml_plugins as $key2 => $xml_plugins){ if (($global_plugins == $xml_plugins) && ($plugin_verso[$key] == $xml_plugin_version[$key2])){ echo 'Exact match'; }else{ echo 'Fuzzy match'; } } } For this example the

foreach in method to return value

霸气de小男生 提交于 2020-01-04 15:31:51
问题 def a: Int = { for(i <- Array(1,2,3,4,5)){ if(i == 3) return i } } The above method will not compile, I get the following error: error: type mismatch; found : Unit required: Int for(i <- Array(1,2,3,4,5)){ ^ The expected behaviour is that the method returns 3. What is wrong with my code? 回答1: That is because your lambda in the foreach does guarantee to return a value. If you provide a default return value it should work. def a: Int = { for(i <- Array(1,2,3,4,5)){ if(i == 3) return i } 0 } 回答2

Single PHP Function To Replace Text With Emoticons Or Filter Words

纵然是瞬间 提交于 2020-01-04 14:06:15
问题 So I'm trying to find a way to build a function that will replace text with an image if it's an emoticon or with a filtered word if it is a prohibited word. I've taken a look at this code: $smiles = array( 'xD' => 'devil.png', '>:)' => 'devil.png', 'x(' => 'angry.png', ':((' => 'cry.png', ':*' => 'kiss.png', ':))' => 'laugh.png', ':D' => 'laugh.png', ':-D' => 'laugh.png', ':x' => 'love.png', '(:|' => 'sleepy.png', ':)' => 'smile.png', ':-)' => 'smile.png', ':(' => 'sad.png', ':-(' => 'sad.png

Single PHP Function To Replace Text With Emoticons Or Filter Words

左心房为你撑大大i 提交于 2020-01-04 14:02:08
问题 So I'm trying to find a way to build a function that will replace text with an image if it's an emoticon or with a filtered word if it is a prohibited word. I've taken a look at this code: $smiles = array( 'xD' => 'devil.png', '>:)' => 'devil.png', 'x(' => 'angry.png', ':((' => 'cry.png', ':*' => 'kiss.png', ':))' => 'laugh.png', ':D' => 'laugh.png', ':-D' => 'laugh.png', ':x' => 'love.png', '(:|' => 'sleepy.png', ':)' => 'smile.png', ':-)' => 'smile.png', ':(' => 'sad.png', ':-(' => 'sad.png

Single PHP Function To Replace Text With Emoticons Or Filter Words

时光毁灭记忆、已成空白 提交于 2020-01-04 14:01:59
问题 So I'm trying to find a way to build a function that will replace text with an image if it's an emoticon or with a filtered word if it is a prohibited word. I've taken a look at this code: $smiles = array( 'xD' => 'devil.png', '>:)' => 'devil.png', 'x(' => 'angry.png', ':((' => 'cry.png', ':*' => 'kiss.png', ':))' => 'laugh.png', ':D' => 'laugh.png', ':-D' => 'laugh.png', ':x' => 'love.png', '(:|' => 'sleepy.png', ':)' => 'smile.png', ':-)' => 'smile.png', ':(' => 'sad.png', ':-(' => 'sad.png

How to break Foreach loop in Powershell?

雨燕双飞 提交于 2020-01-04 09:15:29
问题 I'm looking for a way to break my Foreach loop. This is my code $MyArray = @("desktopstudio","controller","storefront","desktopdirector","licenseserver") $component = "toto,blabla" $component = $component.Split(",") foreach ($value in $component) { if ($MyArray -notcontains $value) { Write-host "Your parameter doesn't match" Write-host "Please use one of this parameter $MyArray" Break } } write-host "I'm here" I don't understand why it's not breaking my code, because this is the result when I

How to break Foreach loop in Powershell?

非 Y 不嫁゛ 提交于 2020-01-04 09:15:20
问题 I'm looking for a way to break my Foreach loop. This is my code $MyArray = @("desktopstudio","controller","storefront","desktopdirector","licenseserver") $component = "toto,blabla" $component = $component.Split(",") foreach ($value in $component) { if ($MyArray -notcontains $value) { Write-host "Your parameter doesn't match" Write-host "Please use one of this parameter $MyArray" Break } } write-host "I'm here" I don't understand why it's not breaking my code, because this is the result when I

Displaying objects using foreach loop

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 07:52:11
问题 I am having a problem while retrieving data from an ArrayList and displaying them into textboxs. I am getting an error: Unable to cast object of type 'Lab_9.Book' to type 'Lab_9.Magazine' . I tried use 2 foreach loops but that seems to be out of the question. How could I avoid this problem? Problem occurs here: // Displaying all Book objects from pubs ArrayList. foreach (Book list in pubs) { bookNumber++; // Count books from the begining. // Displaying and formating the output // in