I want to modify an array cell, which I can do when I know the cell as a number. However here my cell position is given by $i.
pomme[`${i}`]=""
I tried without the `` and it doesn't work either?
How am I suppose to do it?
You don't need the quotes. Just use ${i}, or even $i:
pomme[${i}]=""
Or
pomme[$i]=""
Related
I have a combobox which has an array of Strings such as "Alice", "Bob",and "Charlie" and a string box where user can type. If user types "Bob"in the string box I want to print its index in the combobox, which is 1. Similarly if it is "Charlie" then I want to print "2". I would like to perform this with conditional exit with a for loop, but I am not sure how to return the index when the values are matched.
Thanks
Need to handle the case where the index is not found.
Need to put "String" outside the For Loop so the value is only read once instead of being read on every iteration.
The answer above is correct because you said in your question that you wanted to use the conditional terminal. There is a simpler way without the conditional terminal. I'm including the simpler way here for completeness. The picture below exactly what the picture above does but with a lot less wiring.
I got it working with this.
I converted Combo box to an array of strings and passed to a loop where I compared each instance of combo box with a string and if they are the same then exit then the last index gets printed.
I would like to remove a specific element from an array, not by index because the index value of that item is not static.
myarray.splice(myclip, 1);
When I use this code instead flash removes the first element in the array.
Is there something I am missing here?
Documentation of splice()
Both parameters need to be integers, the first one is the position of the element you want to delete, and the second one is the amount of elements you want to delete. Try myarray.splice(myarray.indexOf(myclip),1);
Don't know why it would only remove the first element in your snippet, maybe internally it casts myclip to 0? Doesn't matter, use indexOf. If that doesn't work, for loop through the array to get the position first.
I am trying to do a sumproduct such as
=SUMPRODUCT(A1:A8,{8,7,6,5,4,3,2,1})
but it give #VALUE! error,
While it is gives a valid value for
=SUMPRODUCT({8,7,6,5,4,3,2,1},{8,7,6,5,4,3,2,1})
Or
=SUMPRODUCT(A1:A8,A1:A8)
According to my understanding it only works if all inputs are of Range or Array type, but not when there are both. Is there any way to make it work?
or you can use ; for vertical array :
=SUMPRODUCT(A1:A8,{8;7;6;5;4;3;2;1})
{8,7,6,5,4,3,2,1} is horizontal array similar to horizontal range like A1:H1 which will not work well with the vertical range A1:A8
I can't test it, but another way can be with the Row function:
=SUMPRODUCT(A1:A8,9-Row(A1:A8))
=SUMPRODUCT(TRANSPOSE(D3:D10),{8,7,6,5,4,3,2,1})
EDIT: Above code works if entered as array forumla
=SUMPRODUCT(D3:D10,TRANSPOSE({8,7,6,5,4,3,2,1}))
works without entering as array formula.
Alright let me explain detailed my question
this below image is displaying my matrix where i want to copy my data
Alright now what i want to do that is as you can see 1x4 cell
i want to copy it as an array to another variable such as
input_values=ones(1,4);%init
input_values=input_matrix_training(1);
So at the above i am trying to copy the elements in that cell array which is row 1 to the input_values array. But if i do as i above i am getting this instead of the values that array contains. ty
instead of above it should be like
The other values are a cell, and are thus best referenced with {} instead of (). Also, sometimes they need to be wrapped into [], depending on the format. Plus the fact that you don't need to initialize input_values, and what you should do becomes this:
input_values=[input_matrix_training{1}];
Or you can just use cell2mat
input_values=cell2mat(input_values(1));
So what I'm trying to achieve is assign multiple values in to a smarty array on the indexes that I want. It's hard to describe it, so I'll just show it:
{assign var='paymentTypes'
value=','|explode:"$paymentMethods[50],$paymentMethods[51],
$paymentMethods[11],$paymentMethods[10],$paymentMethods[12],
$paymentMethods[99],$paymentMethods[100]"}
(Formatted for readability)
So now I have a paymentTypes array with the values placed on the keys starting from 0. What I want is to keep the keys that were in paymentMethods array - 50, 51, 11.. etc.
And it has to be done totally in Smarty template file. Thanks for any ideas.
I've found a workaround. The needed associative array was for a HTML Select tag. So I just used {html_options} with value and output attributes instead of options. I assigned one array just for values and another just for output.
I had this:
{html_options options=$paymentTypes}
But I didn't want to show all of the values from paymentTypes array, but I had to have them in the array. So what I did was this:
{assign var='paymentTypesOutput' value=','|explode:"$paymentTypes[50],
$paymentTypes[51],$paymentTypes[11],$paymentTypes[10],$paymentTypes[12],
$paymentTypes[99],$paymentTypes[100]"}
{assign var='paymentTypesValues' value=','|explode:"50,51,11,10,12,99,100"}
{html_options values=$paymentTypesValues output=$paymentTypesOutput}
It's not the most elegant solution - but it works.