Hi everyone
I have some problem to order an array by a field of this, here i leave the example
foreach($xml as $site){
echo '<div><a href="'.$site->loc.'">'.$site->loc.'</a>' .$site->padre.'</div>';
}
Some times the filed $site->padre is empty but i'd like to order by $site->padre alphabetical
i saw example with usort but i don't understand how to work it.
Thanks in advance.
Cheers
I have a 4D array of measurements in Matlab. Each dimension represents a different parameter for the measurement. I want to find the maximum and minimum value and the index (i.e. which parameter) of each.
What's the best way to do it? I figure I can take the max of the max of the max in each dimension, but that seems like a kludge.
Hi,
Basically I'm trying to add a search function to my iPhone app, but I'm not having much luck at the moment. I've downloaded the Apple provided Table Search app, and have copied across the code to mine. It builds OK, but here's the problem. Unlike the Apple example, all my data is stored in an array, that is accessed by calling [ciParser.currentArray].
Any ideas on how to change the code to suit my needs? I'm getting an error "Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)'" whenever I click on the search bar and the app exits. Below is the code in particular that the debugger highlights as being troublesome.
Apparently this error means the database trying to be searched is empty, but I could be wrong.
FYI my app downloads and parsers an RSS feed using a class which is referenced by ciParser - which in turn stores the downloaded content in an array that I need to search.
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
/*
If the requesting table view is the search display controller's table view, configure the cell using the filtered content, otherwise use the main list.
*/
CurrentItem * nextCurrentItem=[ciParser.currentArray objectAtIndex:indexPath.row];
if (tableView == self.searchDisplayController.searchResultsTableView)
{
(Code which debugger points to as being wrong) nextCurrentItem = [self.filteredListContent objectAtIndex:indexPath.row];
}
else
{
nextCurrentItem = [ciParser.currentArray objectAtIndex:indexPath.row];
}
NSString*settingValue = [[NSUserDefaults standardUserDefaults]stringForKey:@"state"];
if ([settingValue isEqualToString:@"New South Wales"]) {
cell.textLabel.text=nextCurrentItem.title;
}
else if ([settingValue isEqualToString:@"Western Australia"]) {
cell.textLabel.text=@"The FESA does not provide any Current Incident reports.";
}
else if ([settingValue isEqualToString:@"Victoria"]) {
cell.textLabel.text=nextCurrentItem.title;
}
else if ([settingValue isEqualToString:@"South Australia"]) {
cell.textLabel.text=nextCurrentItem.title;
}
else if ([settingValue isEqualToString:@"Tasmania"]) {
cell.textLabel.text=nextCurrentItem.title;
}
// Set up the cell...
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
Hello all,
It seems to me that this should work but I cant see what exactly is the problem.
The error Im receiving is "DDROA is not defined"
Could anyone help enlighten me.
var DDROA = {
AllowedRoutes : {
AR0 : {text : 'SomeText', value : 'SomeValue'},
AR1 : {text : 'SomeText2', value : 'SomeValue2'}
},
RouteContext : {
RC0 : {text : 'None', value : '0',
AllowedRoutes : new Array(
DDROA.AllowedRoutes.AR0 // An error occurs here
)
}
}
}
how do it turn a multidimensional array like:
$fruits['apples']['blue'] = 24;
$fruits['bananas']['blue'] = 12;
$fruits['apple']['red'] = 34;
$fruits['gooseberries']['orange'] = 4;
$fruits['oranges']['red'] = 12;
into a cross referenced table like:
Thanks!
I have a 4D array of measurements in Matlab. Each dimension represents a different parameter for the measurement. I want to find the maximum and minimum value and the index (i.e. which parameter) of each.
What's the best way to do it? I figure I can take the max of the max of the max in each dimension, but that seems like a kludge.
I have an array of numbers:
@numbers = 1,2,3,6,8,9,11,12,13,14,15,20
and I want to print it this way:
1-3,6,8-9,11-15,20
Any thoughts? Of course I tried using the most common "looping", but still didn't get it.
I have this months array:
["January", "March", "December" , "October" ]
And I want to have it sorted like this:
["January", "March", "October", "December" ]
I'm currently thinking in a "if/else" horrible cascade but I wonder if there is some other way to do this.
The bad part is that I need to do this only with "string" ( that is, without using Date object or anything like that )
What would be a good approach?
I got stuck again. Can't overcome this step: loop through (in a form of checkboxes) pallets based on the lot drop down list selection, so it can be further submitted to complete the table. Please, please help.
So, basically, first submit button (drop down menu) brings into the table lot number and description and also checkboxes to choose pallets.
Second submit button (checboxes) brings into the table pallets numbers and weights.
Thank you for any help.
<?php
mysql_connect('localhost','user','');
mysql_select_db('base');
$query="SELECT DISTINCT lot_number FROM pl_table";
$result=mysql_query($query);
?>
<form action="" method="POST">
<select name="option_chosen">
<option>-- Select lot --</option>
<?php
while(list($lot_number)=mysql_fetch_row($result)) {
echo "<option value=\"".$lot_number."\">".$lot_number."</option>";
}
?>
</select>
<input type='submit' name='submitLot' value='Submit' />
</form>
<!-- need help here
<h4>-- Select pallets --</h4>
<form action="" method="POST">
<input type='submit' name='submitPal' value='Submit'/>
</form>
-->
<table border="1" id="table">
<tr>
<th width=80 height=30>Lot<br/>number</th>
<th width=110 height=30>Description</th>
<th width=90 height=30>Pallet<br/>number</th>
<th width=60 height=30>Net</th>
<th width=60 height=30>Gross</th>
</tr>
<?php
if($_SERVER['REQUEST_METHOD'] =='POST')
{$option_chosen=$_POST['option_chosen'];
$query="SELECT * FROM pl_table WHERE lot_number='$option_chosen'";
$run=mysql_query($query);
$row=mysql_fetch_array($run, MYSQLI_ASSOC);
echo "<tr><td>".''."</td>";
echo "<td rowspan='5'>".$row['descr']."</td>";
echo "<td><b>".'Total weight'."<b></td>";
echo "<td>".''."</td><td>".''."</td></tr>";
echo "<td>".$row['lot_number']."</td>";
echo "<td colspan='3'>".''."</td>";
//This to be echoed when "select pallets" submited
//echo "<tr><td>".$row['lot_number']."</td>";
//echo "<td>".$row['pallet_number']."</td>";
//echo "<td>".$row['net']."</td><td>".$row['gross']."</td></tr>";
}
?>
</table>
the table
+--------------------------+-------------------------+---------+-------+
| id | lot_number | descr | pallet_number | net | gross |
+--------------------------+-------------------------+---------+-------+
| 1 | 111 | black | 1 | 800 | 900 |
| 2 | 111 | black | 2 | 801 | 901 |
| 3 | 111 | black | 3 | 802 | 902 |
| 4 | 222 | white | 1 | 800 | 900 |
| 5 | 222 | white | 2 | 801 | 901 |
| 6 | 222 | white | 3 | 802 | 902 |
+--------------------------+-------------------------+---------+-------+
I have an array of numbers:
@numbers = 1,2,3,6,8,9,11,12,13,14,15,20
and I want to print it this way:
1-3,6,8-9,11-15,20
Any thoughts? Of course I tried using the most common "looping", but still didn't get it.
I'm getting "illegal offset type" error for every iteration of this code. Here's the code in case anyone can help:
$s = array();
for($i=0;$i<20;$i++){
$source = $xml->entry[$i]->source;
$s[$source] += 1;
}
print_r($s)
Any ideas. Thanks in advance.
What language is smart so that it could understand 'variable a = 0 , 20, ..., 300' ? so you could esely create arrays with it giving step start var last var (or, better no last variable (a la infinit array)) and not only for numbers (but even complex numbers...)
Hey folks,
I have a variable holding values separated by a comma (Implode), I'm trying to get the total count of the values in that variable however, count() is just returning 1.
I've tried converting the comma separated values to a properly formatted array which still spits out1.
So heres the quick snippet where the sarray session equals to value1,value2,value3:
$schools = $_SESSION['sarray'];
$result = count($schools);
Any help would be appreciated.
Hello, with the hash below, I would like the clients array's reference :
my $this =
{
'name' => $name,
'max_clients' => $max_clients,
'clients' => ()
};
I can't do "\$this{'clients'};" to retrieve the reference.
What would be the best way to extract a column out of mysql results set? My result set is like:
[0] = ('id'=>1, 'name'=>a),
[1] = ('id'=>2, 'name'=>b),
[2] = ('id'=>3, 'name'=>c)
How can I extract 'name' column as an array from this? I can do it using for loop. But wondering if there are any better reusable solution?
Can I pass arrays to functions just as I would do with primitives such as int and bool?
Can I pass them by value?
How does the function know of the size of the array it is passed?
This is the first time I have manipulated hashes and arrays in this way -- and it is working. Basically, for every key there are multiple values that I want to record and then print out in the form "key -- value -- value -- val..."
My code is as follows. I am surprised that it works, so concerned that it works "by mistake". Is this the correct way to accomplish this task, or is there a more efficient or appropriate method?
while ($source =~ m/(regex)/g) { #Get all key names from source
$listkey = $1; #Set current list key to the current regex result.
$list{$listkey} = ++$i unless $list{$listkey}; #Add the key to the hash unless it already exists.
$list{$listkey} = [] unless exists $list{$listkey}; #Add an array for the hash unless the hash already exists.
while ($loopcount==0) {
if ($ifcount==0) {
$listvalue=result_of_some_function_using_list_key; #Get the first list value from the list key.
$ifcount++; #Increment so we only get the first list value once.
} else {
$listvalue=result_of_some_function_using_list_value; #Update the last list value.
}
if ($listvalue) { #If the function returned a value...
push @{$list{$listkey}}, $listvalue; #...then add the value to the hash array for the key.
} else { #There are no more values and we need a new key.
$listkey=0; #Reset variable.
$domain=0; #Reset variable.
$loopcount++; #Increment loop counter to exit loop.
}
}
$ifcount=0; #Reset count variable so the next listvalue can be generated from the new key.
$loopcount=0; #Reset count variable so another loop can begin for a new key.
}
foreach $listkey (keys %list) { #For each key in the hash.
print "$listkey --> "; #Print the key.
@values = @{$list{$listkey}}; #Reference the arrays of the hash.
print join ' --> ', @values; #Print the values.
print "\n"; #Print new line.
}
Is there any efficient way in python to count the times an array of numbers is between certain intervals? the number of intervals i will be using may get quite large
like:
mylist = [4,4,1,18,2,15,6,14,2,16,2,17,12,3,12,4,15,5,17]
some function(mylist, startpoints):
# startpoints = [0,10,20]
count values in range [0,9]
count values in range [10-19]
output = [9,10]
I just wonder how array_diff() works.And obviously it couldn't work as follows
function array_diff($arraya, $arrayb)
{
$diffs = array();
foreach ($arraya as $keya => $valuea)
{
foreach ($arrayb as $valueb)
{
if ($valuea == $valueb)
{
break;
}
$diffs[$keya]=$valuea;
}
}
return $diffs;
} //couldn't be worse than this
Hope someone can show me some better solution.
Thanks.
i need a solution for array_replace_recursive, because my php-version isnt high enough.
i wat to use this code
$_GET = array_replace_recursive($_GET, array("amp"="&"));
easy, isnt it?
Glubber
Hello, how I can use array acces with my static class?
F.e. I like to execute next script:
class A {
...
}
A['p'] = 15;
echo isset(A['p']) ? A['p'] : 0;