Author Topic: [php] Sorting Support  (Read 1940 times)

LavaThemes

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 757
  • Reputation: 34
  • Aspiring Developer
  • iDevices: iTouch 4
[php] Sorting Support
« on: August 31, 2011, 03:12:36 pm »
Code: (php) [Select]
<?php
$string 
"Hello Ww";
foreach (
count_chars($string1) as $i => $num)
{
   if (
chr ($i) == " ") {
      echo 
"| Space - $num |\n";
      continue;
   }
   if (
chr ($i) == "\n") {
      echo 
"| Enter - $num |\n";
      
   }
   else {
      echo 
"| " chr($i) , " - $num |\n";
   }
}
?>

I need to sort the characters by the value of $num. Sort() only works with arrays.

h4ck3rpr0n3

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3061
  • Reputation: 130
  • Developer, Genius :P :P
  • Badges:
  • Computers: HP Pavillion g7: Windows 7, BT5 R1, Ubuntu 12.04, Windows 8, Linux Mint
  • iDevices: ipod touch 3g, ipod touch 2g
Re: [php] Sorting Support
« Reply #1 on: August 31, 2011, 03:23:20 pm »
i'm sorry, i haven't learned php yet (or i would help you), but why don't you just make it into an array? i know it might be a bit harder to get to where you want to go with it but atleast then you can use the sort() function or whatever they call it in php haha.
goals:
[] get developer status
[X] get 30+ karma
[X] get to hero member
[X] become part of the staff

languages i know:
JavaScript
CSS
HTML
PHP
C
C++
Cython
Python

LavaThemes

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 757
  • Reputation: 34
  • Aspiring Developer
  • iDevices: iTouch 4
Re: [php] Sorting Support
« Reply #2 on: September 01, 2011, 09:32:52 am »
Anyone?

C0deH4cker

  • Hero Member
  • *****
  • Posts: 2849
  • Reputation: 129
  • I am leaving iNinjas. Contact me via email.
  • Badges:
  • iDevices: iPhone 4S 16gb Black (5.1.1), iPad 2 32gb White (5.0.1), iPod Touch 2G 8gb (4.2.1)
Re: [php] Sorting Support
« Reply #3 on: September 01, 2011, 12:52:02 pm »
use python

h4ck3rpr0n3

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3061
  • Reputation: 130
  • Developer, Genius :P :P
  • Badges:
  • Computers: HP Pavillion g7: Windows 7, BT5 R1, Ubuntu 12.04, Windows 8, Linux Mint
  • iDevices: ipod touch 3g, ipod touch 2g
Re: [php] Sorting Support
« Reply #4 on: September 01, 2011, 01:17:47 pm »
idt he knows python... we could help though! but you could ask admiral for php help, he knows it.
goals:
[] get developer status
[X] get 30+ karma
[X] get to hero member
[X] become part of the staff

languages i know:
JavaScript
CSS
HTML
PHP
C
C++
Cython
Python

Don't like seeing ads? Click here to register!

Trcx528

  • Haxor
  • Hero Member
  • *****
  • Posts: 4502
  • Reputation: 166
  • Google it!
    • iNinjas
  • Badges:
  • Computers: 13" 2011 Macbook Pro, 120 GB SSD and 16 GB of Ram
  • iDevices: None
Re: [php] Sorting Support
« Reply #5 on: September 01, 2011, 02:35:11 pm »
Admiral is with out power ATM.

LavaThemes

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 757
  • Reputation: 34
  • Aspiring Developer
  • iDevices: iTouch 4
Re: [php] Sorting Support
« Reply #6 on: September 01, 2011, 02:44:33 pm »
Ok guys I think I can get it. If it doesn't work I'll do it in python.

C0deH4cker

  • Hero Member
  • *****
  • Posts: 2849
  • Reputation: 129
  • I am leaving iNinjas. Contact me via email.
  • Badges:
  • iDevices: iPhone 4S 16gb Black (5.1.1), iPad 2 32gb White (5.0.1), iPod Touch 2G 8gb (4.2.1)
Re: [php] Sorting Support
« Reply #7 on: September 01, 2011, 03:00:46 pm »
Python FTW!

h4ck3rpr0n3

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3061
  • Reputation: 130
  • Developer, Genius :P :P
  • Badges:
  • Computers: HP Pavillion g7: Windows 7, BT5 R1, Ubuntu 12.04, Windows 8, Linux Mint
  • iDevices: ipod touch 3g, ipod touch 2g
Re: [php] Sorting Support
« Reply #8 on: September 01, 2011, 04:35:25 pm »
Python FTW!
+infinity!

Admiral is with out power ATM.

i know i could text him and ask him haha.
goals:
[] get developer status
[X] get 30+ karma
[X] get to hero member
[X] become part of the staff

languages i know:
JavaScript
CSS
HTML
PHP
C
C++
Cython
Python

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: [php] Sorting Support
« Reply #9 on: September 05, 2011, 12:27:12 am »
try using strlen()
« Last Edit: September 05, 2011, 12:28:58 am by Admiral »

Don't like seeing ads? Click here to register!

LavaThemes

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 757
  • Reputation: 34
  • Aspiring Developer
  • iDevices: iTouch 4
Re: [php] Sorting Support
« Reply #10 on: September 05, 2011, 07:13:01 am »
Strlen() just measures the whole string. I need the # of instances of all letters in that string.

C0deH4cker

  • Hero Member
  • *****
  • Posts: 2849
  • Reputation: 129
  • I am leaving iNinjas. Contact me via email.
  • Badges:
  • iDevices: iPhone 4S 16gb Black (5.1.1), iPad 2 32gb White (5.0.1), iPod Touch 2G 8gb (4.2.1)
Re: [php] Sorting Support
« Reply #11 on: September 05, 2011, 09:39:01 am »
I dont think this will work, but try it:
Code: ("php") [Select]
<?php
$mystr 
"acbdfets";
$myarr = [];
foreach(
$mystr as $mychr)
{
$myarr += $mychr;
}
sort($myarr);
?>


Would that work? Its been so long since ive learned php...